Linux commands to manage files and directories
command | Features | command | Features |
pwd | Displays the current directory | ls | Look under directory |
cd | Change directory | cat | Display file contents |
grep | Find a character in the file | cp | Copy files |
touch | Create a file | mv | Moving Files |
rm | Delete Files | rmdir | Remove directory |
1. pwd command
English explanation of the command to print working directory (print working directory). Enter the pwd command, Linux will output the current directory.
2. cd command
the cd command to change directories.
cd / to the root directory
cd ~ go / home / user user directory under
usr directory under cd / usr directory to the root ------------- absolute path
cd test Goes test subdirectory of the relative path -------
3. ls command
ls command to view the contents of the directory.
Options | meaning |
-a | Directory lists all files, including hidden files |
-l | The details listed in the directory, including permissions, owner, group, size, creation date, whether the file is a link, etc. |
-f | Listed file displays file types |
-r | Reverse, include the contents of the directory from back to front |
-R | Recursive, this option recursively lists the contents of the current directory in all subdirectories |
-s | Size, sort by file size |
-h | Display size of the file, such as with K, M, G as a unit to a human-readable manner |
ls -l examples.doc | All of the information listed files examples.doc |
4. cat command
The cat command can be used to merge files, it can also be used to display the contents of an entire file on the screen.
cat snow.txt This command displays the contents of the file snow.txt, ctrl + D to exit the cat.
5. grep command
The maximum function grep command is to find a specific string in a pile of documents.
grep money test.txt
The above command to find money in the string in test.txt, grep lookup is case-sensitive.
6. touch command
touch command to create a new file, he can create a blank file, you can add text and data therein.
touch newfile This command creates a blank file called newfile in.
7. cp command
cp command to copy files to copy the file, enter the command:
cp <source filename> <target filename>
cp t.txt Document / t This command will t.txt file copied to the Document directory and named t.
Options | meaning |
-i | Interaction: If the file will overwrite files on the destination, he will be prompted to confirm |
-r | Recursive: This option will copy the entire directory tree, subdirectories and other |
-v | Details: display the file copy progress |
8. mv command
mv command to move files.
Options | Explanation |
-i | Interactive: If you select a file overwrites the file in the target, he will be prompted to confirm |
-f | Forced: it will surpass the interactive mode, move files without prompting, are very dangerous option |
-v | Details: Shows the progress of moving files |
mv t.txt Document t.txt the file to the directory in the Document.
9. rm command
rm command to delete a file.
Options | Explanation |
-i | Interactive: prompt to confirm the deletion |
-f | Forced: instead of interactive mode, not prompted to confirm the deletion |
-v | Details: delete the file progress display |
-r | Recursive: deletes a directory and all files and subdirectories in which |
rm t.txt This command deletes the file t.txt
10. rmdir command
dir rmdir command to delete a folder, dir must be an empty folder.