Linux Move (mv) Command

The Linux move command (mv) is one of the essential commands, which can be very useful in Linux, Unix, and AIX.  The primary purpose of the move command is obviously to move files, and of course, directories.   The move command may also be used to rename files and to make backups.

Move Command Syntax

$ mv [options] source (file or directory)  destination

Move Command options

option description
mv -f force move by overwriting destination file without prompt
mv -i interactive prompt before overwriting
mv -u update – move when the source is newer than the destination
mv -v verbose – print source and destination files
MV – t explicitly saying to move the file or directory here, rather trying to fit everything into the last argument.
mv * Move all (Multiple) files to a specific director without listing by name

For More move command details see the Linux documentation manuals using the man command

$ man mv

mv command examples

Here are some quick and very simple move command (MV) examples for reference.

Move Move to files  to the /Archive/ directory:

$ mv happy.txt garden.txt /Archive/

Move all “.txt” files in the current directory to subdirectory backup:

$ mv *.txt backup

Move all files in subdirectory ‘backup’ to current directory:

$ mv backup/*

Rename file happy.txt to happy.bak filename:

$ mv happy.txt happy.bak

Rename directory backup to backup2:

$ mv backup backup2

Update – move when happy.txt is newer or missing in target directory:

$ mv -u happy.txt backup

Move happy.txt and prompt before overwrite backup / happy.txt:

$ mv -v happy.txt backup

Useful Links – Linux

Here are a few useful references for Linux, which may be helpful.

Linux Documentation

Bash Documentation

Links for Major Linux Distributions

CentOS

Red Hat Enterprise Linux (RHEL)

Ubuntu

8 Most Useful Linux Commands For Beginners

Do you think that the command lines are an old-fashion leftover from previous decades or an antiquated way of using a PC? Think again. Indeed, it is one of the most powerful and flexible ways to perform and manage in Linux. If you come from the comfort of a Mac or Window desktop, however, it can be a bit intimidating to get used to Linux commands. Everything is secretive, dark, and anything but friendly to beginners. That’s why we have rounded up this short list of the most useful Linux commands with examples. Keep reading and speed up your learning journey with Linux.

1. Ls command – list files

Ls is one of the most basic and common commands in Linux. You can use it to print contents in the current working directory and see the list of files, directories, or folders on your Linux system.
For instance, the command “ls tourism” will display the users every folder store inside the overall “tourism” folder. Keep in mind that directories and files will be denoted in different colors, which can be selected in the system.
You would also use the command “ls – R” to display all files both in the directories and subdirectories. Since Linux commands are case sensitive, make sure to enter “R” instead of “r” to avoid an error.

2. Cat command – create and view files

You can use the “cat” command to show text files. Also, it would be used for creating, combining, and copying text files. For example, use “cat linux_tip” to get inside the linux_tip file and read its contents on the screen.
To combine two text files “linux_tip_1” and “linux_tip_2, you can enter the following command “cat linux_tip_1 linux_tip_2 > linux_tip”. Keep in mind that only text documents would be combined and shown with this command.

3. Rm command – delete files

The “Rm” command can be used for removing files or directories from your Linux system without confirmation. The syntax is simple “Rm name_deleted_file.”
For example, the command “rm computer_science” will immediately remove the file or directory named “computer_science” from your computer. Make sure to consider carefully before using this command because you cannot get it back.

4. mv command – move and rename files

To move and rename files, the “mv” command will be used. Here is the basic syntax for this task: “mv filename new_location.”
Suppose that you need to move the file name “english_class” to location “/home/school/documents”, just enter the command “mv english_class /home/school/documents.” Keep in mind that this command requires the permission of users.
The syntax for renaming a file is “mv filename newname”. An example command is “mv english_class french_class”

5. Mkdir – create directories

If you want to create a new directory in your Linux system, then you can use the “mkdir” command. The syntax is “mkdir new_directory.”
For instance, you can create a new directory named “final homework” by typing the following command “mkdir final_homework.” In case you do not want to make a parent directory manually, add the -p argument. Keep in mind that it is -p, not -P. Everything in Linux is case sensitive.

6. Rmdir command – remove directories

In contrast with the mkdir command, you can use the rmdir command to remove a directory. The syntax is similar: “rmdir removed_directory.”
If you enter the following command “rmdir basketball_data”, it will immediately delete the directory named “basketball_data”. Always check carefully to make sure that there is no sub-directory or file under the deleted directory. If possible, it is always better to delete the sub-directory or files first before moving to the parent one.

7. Man command – seek help in Linux

“Man” simply stands for manual. You can use this command to access a reference book of the Linux system, which is quite similar to the “Help” file in many popular applications or software. To seek help on any commands that you don’t understand, just enter “ma command_name”. The terminal will open a manual page for the typed command.
For example, if you enter “man ls”, the terminal will provide you with basic information on the “ls” command.

8. History command – view previous commands

As you can guess from the name, the “history” command can be used to display all of the commands that you just used previously for the current session. This can be helpful in referring to the old commands and re-entering or re-using them in the next operations.

Related References

Linux – What is yum?

Linux
Linux

In simple terms, yum is a, command-line interface, package manager utility for computers running the Linux operating system, which augments the RPM Package Manager capabilities. yum is the primary tool for getting, installing, deleting, querying, and managing RPM software packages. Also, yum is used in Red Hat Enterprise Linux (RHEL) versions 5 and later.

Linux – how to display file system disk space statistics

Linux
Linux

In Linux there are lot of ways to disk size and/or space, but the ‘Disk Filesystem’ (df) command is old reliable and has been around a long time.   The ‘df’ command provides a summary of disk space and free space, which I find myself coming back to time after time.

Basic Command Format

DF -<<Option>>   <<File>>

Example ‘Disk Filesystem’, Command

df -h

  • -h = Human readable in MegaBytes

For more details in Linux

df –help

Example Command Output

root@BlogSrvr1 /]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_BlogSrvr1-lv_root

36G   34G   16M 100% /

tmpfs                 3.9G     0  3.9G   0% /dev/shm

/dev/sda1             477M   33M  419M   8% /boot

/dev/mapper/vg_BlogSrvr1-LogVol03

11G   27M  9.9G   1% /data

/dev/mapper/vg_BloSrvr1-lv_home

4.8G   33M  4.6G   1% /home

/dev/mapper/vg_BlogSrvr1-LogVol04

25G   13G   11G  55% /opt/IBM

/dev/mapper/vg_BlogSrvr1-LogVol05

11G  6.0G  3.7G  62% /scratch

/dev/mapper/vg_BlogSrvr1-LogVol06

11G   27M  9.9G   1% /tmp/dev/shm

Linux – How to compress an entire directory

Linux
Linux

From time to time there is a need to package up a folder for any number of reasons which may include things like:

  • Migration
  • Movement to a new location
  • Movement to a new server
  • To keep a backup
  • Or simply to save space

Compressing a folder is folder can be very useful, but for those of us who don’t do it all the time, it is nice to have a pattern to follow.  Also, even an experienced user can get brain cramp, if they have not had a reason to compress a folder in a while. So, here is a simple pattern to follow to compress a folder and its contents.

Basic Command Format

tar -zcvf <<archive-name>>.tar.gz <<directory-name>>

Example Compress Command

tar -zcvf  blog_files_backup.tar.gz   sqlfiles

Linux tar command line options used here

  • -z = Compress archive using gzip program
  • -c = Create archive
  • -v = Verbose i.e display progress while creating archive
  • -f = Archive File name

For help with the tar command in Linux

To get additional detail on the tar command in Linux, just need to type:

 tar -?

How to stop and restart Cognos Service from Linux command line

stop and restart cognos service from linux command line
stop and restart Cognos service from Linux command line

I don’t do this very often but recently had to look this up to help out a project.  Stopping and restarting a Cognos from a Linux command line is relatively simple, just a couple of commands.

  • Log on to the reporting server as Root user or a non-root user with administrative privileges.
  • Find the path to install bin directory.  I use this find command, but you can do what works for you:   find . -name “cogconfig.sh”
  • Launch an and navigate to the bin directory as follows: <Cognos_Home>/bin64
  • Where <Cognos_Home> is the installation location of the Cognos® application.
  • Do the following one or both of the following, according to what you are attempting to do:
    • To start the service, enter the following command: ./cogconfig.sh -s
    • To stop the service, enter the following command: ./cogconfig.sh -stop

Related References