1. File operation commands
0) List all files and directories in the current directory.
ls dir
1) View the detailed list information in the current directory, including permission attributes
ll ls -l
2) View all files in the current directory whose names start with cron
ll cron*
3) Get the current directory address?
pwd
4) Exit to the upper-level directory?
cd ..
5) Go back to where you were last time?
cd –
6) Enter the user’s default directory and enter the user’s home directory?
cd ~ cd
7) Access the root directory of the system?
cd /
8) Create a directory?
mkdir test
9) Create multiple directories /a/b/c?
Mkdir -p /a/b/c Create a directory in the root directory
Mkdir -p a/b/c In the current directory
10) How to create a file?
touch tt.txt
11) How do I write a piece of content to a file?
echo hello world>test.txt
If test. TXT is not in the current directory, create the file
Cat >test. TXT CTRL + D save and exit
12) What is the difference between redirection > and >>
> Overwrite old content
>> File append
13) How do I rename a file?
mv test.txt newtest.txt
14) Move the tt. TXT file to the parent directory?
mv tt.txt .. /
15) Move all files in the current directory to /root at one time
mv * /root
16) How to copy tt. TXT to /root directory
cp tt.txt /root
17) Copy the tomcat8080 directory and all directories and files in this directory to the Tomcat8081 directory
cp -r|R tomcat8080 tomcat8081
18) How to delete a file?
The rm test. TXT asked
Rm -f test. TXT No query
19) How do I delete multilevel non-empty directories at one time? (the directory structure is a/b/c/test.txt)
rm -rf a/b/c/test.txt
20) How to delete an empty directory?
rmdir testdir
21) How to delete multi-level empty directories at one time? a/b/c
rmdir -p a/b/c
22) How to package tar files and unpack them?
tar -zcvf mytar.tar test.txt
tar -zxvf mytar.tar
23) How to compress. Zip files and decompress them?
zip myzip.zip test.txt
Unzip -o myzip.zip overwrites the original file without asking
24) How to view the contents of small files? How to view file contents and display line numbers at the same time?
cat test.txt
cat -n test.txt
25) How to view only the first 2 lines of test.txt?
head -2 test.txt
26) How to view only the last 2 lines of test. TXT file?
tail -2 test.txt
27) Dynamically monitor the contents of catalina.out files?
tail -f Catalina.out
28) What is the command for paging through files?
more filename
less filename
29) Count the total lines of text?
wc -l filename
30) What is the command for editing the text content
vi vim
31) How to switch between the three modes of VI
Command mode I- Input mode: -> Bottom line mode
Enter mode ESC -> Command mode
Bottom line mode w Save q exit wq Save exit Q! Forced out of
32) How to view help in Linux
help ls ls –help
man ls
33) How to find a line containing a keyword in a specified file?
grep this filename
34) Find all TXT suffix files in the system
find -type f -name *.txt
-type: indicates the file type
-name: searches by file name
35) Check the free disk space of the disk.
df
36) Switch to user su