Here are some useful Linux commands that are most commonly used that help to learn linux easily.
Creating a directory: To create a directory use the “mkdir” command.
eg: $ mkdir dir7
The $ sign indicates that the user is a normal user.
Copying files.
To copy files use the “cp” command.
Format: cp souce destination.
eg:$ cp file1 file2.
This is simply overwriting a file named file2 over file1. To copy a file to a directory use the following command:
$ cp file1 dir1
dir is the command used to represent a directory.
There are some parameters for copying a file. These parameters are simple to learn and use!
Here are the parameters and its functions:
1. -a Create an archive of the file being copied by preserving their attributes.
2. -b Simply creates a backup of the existing file there by preventing the need to overwrite it.
3. -d Preserve.
4. -f Force the overwriting of existing file and didnot prompt when doing so.
5. -i Like the previous one but prompts when overwriting is needed.
6. -l Create a link to file , not a copy of the file.
7. -p Used to Preserve the attributes of a file.
8. -r Copy files recursively.
9. -R Used to copy directories recursively.
10. -s Create a symbolic link,not a copy of it.
11. -S Used when no backup of the file is needed.
12. -u Usually, used to update a file .
13. -v Verbose mode.
14. -x Used to Restrict the access to copy the file.
eg: cp -l file1 file4 -creates a link between file4 and file1.
Similarly play with other parameters to understand more about them.
Note: You should know a command called “ln”. This command is used instead of cp and it is only used to create hardlinks.
A hard link is used to link file having the same mount point. A hard link is a separate file that contains some additional details about the file in addition to acting as a link to that file.
-s is the parameter is used to create soft links, which are links that are used to link file having different mount points. So always be very careful in creating links with these two parameters.
Renaming a file.
To rename a file we use the mv command, because renaming a file in linux is called moving.
eg: $ mv file2 file4
Here is another example we move or rename a directory:
eg:$ mv dir5 dir6
Deleting a file.
Deleting a file in Linux is called removing, so it is quite easy and the command is rm.
eg:$ rm file1
Here is how to remove a directory: