Commands
There are tons of commands in a Linux system. And I think it is not important to memorize all of them; well, it's kinda impossible. However, once one starts working with a system, one usually gets familiarized the frequently used commands. And of course, the "TAB" button is always helpful.
Command Pattern
All commands in UNIX follow this pattern
command -arg/opt source destination
If the arguments consist of more than one alphabet, it is written as --argument. Different commands have different structures. Some commands don’t need any arguments, some commands use source only, some commands only need destination. You’ll get used to the structures as you keep working with Linux.
pwd (Present Working Directory)
Syntax: command
pwd is used to view absolute path of current working directory that one’s working in.
[root@prime audit]# pwd
/var/log/audit
cd (Change Directory)
Syntax: command destination
cd is used to change a directory. The destination may be absolute or relative path.
# cd /var/log/audit/ | Goes to /var/log/audit |
# cd | Goes to the home directory of the user |
# cd .. | Goes ‘UP’ one level |
mkdir (Make Directory)
Syntax: command -arg destination
This command is used to create new directories/folders.
# mkdir testdir | Creates a new directory ‘testdir’ in pwd |
# mkdir /tmp/testdir2 | Creates a new directory ‘testdir2’ in /tmp |
# mkdir -p /newdir/testdir3/testdir4 | Creates all necessary directories in the path as necessary |
touch (Creates a new empty file)
Syntax: command -arg destination
This command is used to create a new empty file.
# touch testfile | Creates a new file ‘testfile’ in pwd |
# touch /tmp/testfile2 | Creates a new file ‘testfile2’ in /tmp |
ls (list)
Syntax: command -arg destination
This command is used to see the contents of a directory. Contents of a file cannot be viewed by ls.
# ls | Shows content of pwd |
# ls –l | Shows detailed information about content of pwd |
# ls –l /tmp | Shows detailed information about content of /tmp |
# ls –a | Show all files (including hidden) in pwd |
# ls –a /tmp | Show all files (including hidden) in /tmp |
# ls –lh | Shows file size in human readable format |
# ls –alh | Shows all file size in human readable format |
| |
cp (Copy)
Syntax: command -arg source destination
cp is used to copy a file from one location to another one. The address of the source/destination may be absolute or relative path.
# cp f1 /tmp | Copies the file ‘f1’ from pwd to /tmp |
# cp f1 /tmp/f2 | Copies the file ‘f1’ from pwd to /tmp and renames it as ‘f2’ |
# cp /root/f2 /mnt/f32 | Copies the file /root/f1 to /mnt and renames it as ‘f32’ |
# cp -r /root/testdir /tmp/testdir | Copies the directory /root/testdir to /tmp. The ‘-r’ indicates the operation will be recursive i.e. all files and subdirectories in ‘testdir’ will also be copied. |
mv (move)
Syntax: command -arg source destination
cp is used to copy a file from one location to another one. The address of the source/destination may be absolute or relative path.
# mv f1 f2 | Renames ‘f1’ to ‘f2’ |
# mv f1 /tmp | moves the file ‘f1’ from pwd to /tmp |
# mv f1 /tmp/f2 | Moves the file ‘f1’ from pwd to /tmp and renames it as ‘f2’ |
# mv /root/f2 /mnt/f32 | Moves the file /root/f1 to /mnt and renames it as ‘f32’ |
# mv /root/testdir /tmp/testdir | Moves the directory /root/testdir to /tmp. |
rm (Remove)
Syntax: command -arg destination
This command is used to delete files and directories. To delete directories, the option –r must be used.
# rm f1 | Removes file ‘f1’ in pwd |
# rm /root/f2 | Removes file /root/f2 |
# rm –r testdir | Removes the directory ‘testdir’ in pwd |
# rm -rf testdir2 | Forcefully remove the directory ‘testdir2’. Does not ask for confirmation. |
Comments
Post a Comment