“In the Linux system, any thing is file.” In this blog, we are going to see some commands which can manipulate files, and those operations include “copy”,“move”,“rename”,“create”,“remove” and “create link”.
- Before we learn those commands, we need know a feature of Linux, “Wildcards”. “Wildcards” provides special characters to help you rapidly specify groups of filenames, so this feature can make file operations more efficient.
Using wildcards allows you to select filename based on patterns of characters. If you used the “Regular Expression”, you would be familar with this feature.
e.g.
List all files which their name contains “32”.
some patterns and rules are shown below:
- Create Directories : “mkdir”
“mkdir” means creating directorie, this command can create one directory or multiple dirs at same time.
e.g. Make a directory
e.g. Make multiple directories
- Copy files and directories : “cp”
“cp” can be used by two ways.
3.1. To copy the single file or directory “item1” to file or directory “item2”
e.g.
3.2. To copy multiple items (either files or directories) into a directory.
e.g.
Tips: We can use this commands with some options
- Move and remove files : “mv”
The “mv” command can move a itme into another item, or we can use it to change item’s name.
4.1. To move or rename file or directory “item1” to “item2”
e.g.
e.g.
4.2. To move one or more items from one directory to another
Tips: We can use this commands with some options
- Remove files and Directories : “rm”
The “rm” command is used to delete files and directories.
e.g.
Tips : We can use this commands with some options
- Hard link and symbolic link
6.1. A hard link is indistinguishable from file itself. When a hard link is deleted, the link is removed but the contents of file itself continue to exit(that is, its space is not deallocated) until all links to the file are deteted.
Tow limitations of hard link:
- A hard link cannot reference a file outside its own file system. This means a link may not reference a file that is not on the same disk portion as the link itself.
- A hard link may not reference a directory.
Creat a hard link:
6.2. Symbolic links were created to overcome the limitations of hard links. Symbolic links work by creating a special type of file that contains a text pointer to the referenced file or directory.
A file pointed to by a symbolic link, and the symbolic link itself are largely indistinguishable from one another. For example, if you write some something to the symbolic link, the referenced file is also written to. However when you delete a symbolic link, only the link is deleted, not the file itself. If the file is deleted before the symbolic link, the link will continue to exist, but will point to nothing. In this case, the link is said to be broken.
Create a symbolic link: