note Linux Command
Front row: The simple introduction to the Linux command line is a memo or a review and consolidation article I gave myself. I hope it will be convenient for me and help beginners get started. This is a simple introduction, including common commands for directory management and file management.
Directory management
pwd
Suppose that the directory where we are currently located is called the working directory. To find the name of the working directory, use the pwd command.
demonstration
[ me@hostname me]$ pwd /home/me
cd
To change your working directory, use the cd command. To do this, type cd followed by the pathname of the desired working directory.
demonstration
[ me@hostname me]$ cd /usr/bin [ me@hostname bin]$ pwd /usr/bin
[ me@hostname bin]$ cd .. [ me@hostname usr]$ pwd /usr
[ me@hostname usr]$ cd ./ bin [ me@hostname bin]$ pwd /usr/bin
ls
The ls command lists the contents of a directory. This is probably the most commonly used Linux command. It can be used in many different ways. below
Command | Result |
---|
ls | Display all files in the current working directory |
ls /bin | Display all files in the bin directory |
ls -l | Display all files including their formats under the current working directory |
ls -l /etc /bin | Display all files including their formats in the etc directory and bin directory |
ls -la .. | Show all files, including hidden files and their formats |
file management
- Cp: Copy the file and its directory location
- Mv: move or rename the file and its directory location
- Rm: delete the file and its directory location
- Mkdir: create a new directory
cp
The cp command copies the file and its directory location. The simplest form is to copy a file to another file:
demonstration
[ me@hostname me]$ cp file1 file2
[ me@hostname me]$ cp file... directory
Other useful cp usage and examples:
Command | Result |
---|
cp file1 file2 | Copy the contents of file1 to file2. If file2 does not exist, create it. Otherwise, overwrite the contents |
cp -i file1 file2 | Same as above, but there will be an override prompt |
cp file1 dir1 | Copy file1 to dir1 |
cp -R dir1 dir2 | Copy the contents of dir1 to dir2. If dir2 does not exist, create it |
mv
The mv command is used to move or rename files and directories.
demonstration
[ me@hostname me]$ mv filename1 filename2
[ me@hostname me]$ mv file... directory
Other useful mv usage and examples:
Command | Result |
---|
mv file1 file2 | If file2 does not exist, then file1 is renamed to file2. If file2 exists, The contents of file2 will overwrite file1 |
mv -i file1 file2 | Same as above, but there will be an override prompt |
mv file1 file2 file3 dir1 | File1, file2, and file3 are moved to dir1. If dir1 does not exist, it will not be executed due to an error |
mv dir1 dir2 | If dir2 does not exist, dir1 is renamed to dir2. If dir1 exists, dir1 is moved to dir2 |
rm
The rm command deletes a file or directory.
demonstration
[ me@hostname me]$ rm file...
[ me@hostname me]$ rm -r directory...
Other useful rm usages and examples:
Command | Result |
---|
rm file1 file2 | Delete file1 and file2 |
rm -i file1 file2 | Same as above, but there will be a deletion prompt |
rm -r dir1 dir2 | Delete dir1 and dir2, including their contents |
When using rm, it should be noted that Linux does not undo the deletion command. That is, once the rm command is executed, the deleted items will really disappear.
mkdir
The MKDIR command is used to create a directory.
demonstration
[ me@hostname me]$ mkdir directory...
This article is written by Chakhsu Lau Creation, adoption Knowledge Sharing Attribution 4.0 International License Agreement.
All articles on this website are original or translated by this website, except for the reprint/source. Please sign your name before reprinting.