cd
This command will change the directory as desired. Few of the cd examples are as follows:
Command Details
cd or cd ~ To go directly to the home directory,
cd .. To go up one level. We also can use like ../../.. for moving
multiple levels in the directory
cd /home/anil To go to anil directory within /home
cp
This command is used to copy the contents of one file into another file. Its syntax is as under:
cp source_path/source_file_name destination_path/destination_file_name
Some of the switches and examples of cp command are as follows:
Command Details
cp /home/anil/myfile1 /myfile2 This will copy myfile1 from anil’s directory within /home/anil to myfile2 in root ( / ) directory.
cp -r dir3 /dir2 This will copy all the contents of directory dir3, within current directory into the directory dir2 within root ( / ) directory.
cp -p myfile2 myfile3 This will copy contents of myfile2 to the file myfile3, but will keep creation date and inode number same as source file
This command is used to remove files as well as directories. Few of the examples of rm command are as follows:
Command Details
rm myfile2 This will remove the file myfile2 in current directory.
rm -i myfile3 This will remove file myfile3 after prompting the user for
confirmation
rm -d myfile3 This will delete the file myfile3, without prompting the user
Note : As the command rm can be very dangerous at times. It is therefore, advised you to run your system in super user mode (i.e. logging with root user’s credentials) only when it is required. And that is why, the Red Hat Linux configures rm as alias for rm -i. ( alias rm=‘rm -i’ ).
mv
This command is used to move the entire file from one place to another. We also can use this command for renaming purposes. If the file is moved within the same volume, the inode number also remains the same. Few of the mv examples are shown here under:
Command Details
mv myfile2 myfile5 This will rename the file myfile2 to file myfile5. The inodes
number of the new file will remain same
mv -i myfile5 myfile6 This command will prompt us before moving the file, if myfile6
file is already there.
mv * /home/anil This command will move all files in current directory to
/home/anil directory.
ln
Many a times it works to link, than to move or copy a file. Links are beneficial for those programs which start at different run levels. Links create another path to existing file. I anil and vijai both are working on the same file named employees, which is within /home/anil, Then instead of copying it on two places we can create a link for it (Copying a file, to other place, will make it altogether a different file). The command for this will be as follows:
# ln /home/anil/employee /home/vijai/employee
Another option for links is to use symbolic link. This allows us to see the linked files. As we can run the following command:
# ln -s /home/anil/employee /home/vijai/employee
This is also known as soft link. In case the original file is deleted, then the soft linked file will point to an empty file.
head , tail
This command provides us the view of first few lines of a file, while the tail command provides view of the last few lines of this file. With the help of switches, we can control the amount of the file that we want to see. For example the following commands:
# tail -n10 myfile Will show last 10 lines of file myfile
# tail 2k myfile Will show last 2KB of file myfile
# head -n10 myfile Will show first 10 lines of file myfile
# head 2k myfile Will show first 2k of file myfile
# head 25b myfile Will show first 25 bytes of file myfile
find
This command looks in the directories and subdirectories for the files of our need. If we want to search for the file named myfile, we can use the following command:
# find / -name myfile
This command will start its search from root ( / ) directory.
No comments:
Post a Comment