LINUX Common Commands Encyclopedia

  

su

The su command is one of the most basic commands, and is often used to switch between different users.

For example, if you log in as user1 and want to switch to user2, just use the following command:

$su user2

Then the system prompts for the user2 password and enters the correct password. You can switch to user2. Once completed, you can use the exit command to return to user1.

A common use of the su command is to become the root user or superuser. If you issue the su command without a user name, the system prompts you to enter the root password, and you can switch to the root user after the input. If you log in as the root user, you can use the su command to become any user on the system without a password.

pwd --Print Working Directory

The pwd command is also one of the most commonly used and most basic commands for displaying the directory in which the user is currently located.

Displays the path name of the working directory. Syntax pwd [ -L |  -P ]

Description

The pwd command writes the full path name of the current directory (from the root directory) to standard output. All directories are separated by /(slash). The first /represents the root directory and the last directory is the current directory.

Flags

-L

If the PWD environment variable contains an absolute path name that does not contain the current directory of the file name (dot) or .. (dot), then Displays the value of the PWD environment variable. Otherwise, the -L flag works like the -P flag.

-P

Displays the absolute path name of the current directory. The absolute path displayed with the -P flag does not include the name of the file that refers to the symbolic link type in the absolute path of the path name.

cd

The cd command not only displays the current state, but also changes the current state. Its use is basically the same as the cd command under dos.

cd .. can enter the previous directory cd - can enter the previous directory

cd ~ can enter the user's home directory

ls (list display current directory The following files and directories ls -l detailed display = ll )

The ls command is the same as the dir command under dos, used to display the contents of the current directory.

If you want to get detailed information, you can use the ls -l command, so you can display the details of the directory contents.

If there are too many files in the directory, you can't display them with one screen. You can use ls -l | More split screen display.

ls [root@linux ~]# ls [-aAdfFhilRS] Directory Name [root@linux ~]# ls [--color={none,auto,always}] Directory Name [root@linux ~] # ls [--full-time] Directory Name Parameters: -a : All files, along with hidden files (files beginning with .) are listed together ~ -A : All files, along with hidden files, but not included. .. These two directories, listed together ~ -d : only list the directory itself, not the file data in the directory -f : directly list the results without sorting (ls presets will be sorted by file name !) -F : Give additional data structures based on files, directories, etc., for example: *: for executable files; /: for directories; =: for socket files; : represents the FIFO file; -h: lists the file capacity in a human-readable way (eg GB, KB, etc.); -i : lists the inode location instead of the archive attribute; -l : long data string Line out, including the attributes of the file, etc.; -n : List the UID and GID instead of the user and group name (UID and GID will be mentioned in the account management!) -r : Reverse the sort result. For example: the original file name is from small to large, the reverse is from large to small; -R: listed together with the contents of the subdirectory; -S: sorted by file size! -t : Sort by time --color=never : Do not give color display according to file characteristics; --color=always : display color --color=auto : Let the system determine whether to give color according to the setting --full-time : Output in full time mode (including year, month, day, hour, minute) --time={atime,ctime} : Output access time or change permission attribute time (ctime) instead of content modification time (modification time)

find

The find command is used to find files.

This command can search by file name, create or modify date, owner (usually the user who created the file), file length, or file type.

The basic structure of the find command is as follows: $find

Which specifies which directory to start searching from. Specify search criteria. Indicates how to find the file. In general, use the -print action to display the entire file path and name.

If there is no such action, the find command does the search and does not display the result, which is equivalent to effort. For example, to search for all files named ye on the system,

can use the following command: $find /-name ye -print This will display all files named ye on the system.

tar

tar was originally used to build tape backup systems and is currently widely used to create file distribution files.

You can create a tar file as follows: $tar cvf

For example, if you want to archive all files in the current directory to ye.tar,

can use the following command: Tar cvf ye.tar *.* To view the contents of the file, change the c option to t.

If you want to browse the contents of the ye.tar file, you can use the following command: $tar tvf ye.tar

To extract the contents of the file, change the c option to x. If you want to retrieve the contents of the ye.tar file into the current directory, you can use the following command: $tar xvf ye.tar

gzip

The gzip command is used to compress files.

For example, if you want to compress the ye.txt file, you can use the following command: $gzip ye.txt

This will compress the file and add the gz extension to the file name to become The file ye.txt.gz. The unzipped file can be implemented with the gzip -d command: $gzip -d ye.txt.gz This will unzip the file and remove the gz extension.

In addition to this, you can use the gunzip command to unzip the file, the same effect as the gzip -d command. The old version of the tar command does not compress the file and can be compressed with gzip. For example: $tar cvf ye.tar *.txt $gzip ye.tar creates a compressed file ye.tar.gz. The new version of tar can directly access and build gzip compressed tar files, just add the z option to the tar command. For example: $tar czvf ye.tar *.txt generates the compressed file ye.tar.gz, $tar tzvf ye.tar *.txt shows the contents of the compressed file ye.tar.gz, and $tar xzvf ye.tar *.txt Take out the contents of the compressed file ye.tar.gz.

mkdir

This command is very simple, almost the same as the dos md command usage, used to create a directory.

cp

The cp command is used to copy files or directories.

The cp command can copy multiple files at once, for example: $cp *.txt *.doc *.bak /home

Files with extensions txt, doc, and bak in the current directory Copy all to the /home directory.

If you want to copy the entire directory and all its subdirectories, you can use the cp -R command.

rm

The rm command is used to delete a file or directory.

The rm command will force the deletion of files. If you want to be prompted for confirmation when deleting, you can use the rm -i command.

If you want to delete a directory, you can use the rm -r command. When the rm -r command deletes a directory, a prompt is displayed for each file or directory deleted. If the directory is too large, it is unrealistic to respond to each prompt.

At this time, you can use the rm -rf command to force the deletion of the directory, so that the -i flag is used as invalid.

mv

The mv command is used to move files and rename files. For example: $mv ye.txt /home

Move the ye.txt file in the current directory to the /home directory,

$mv ye.txt ye1.txt will ye.txt file Renamed ye1.txt.

Similar to the cp command, the mv command can also move multiple files at once, so I won't go into details here.

cat

Displaying the contents of the file from the first line [root@linux ~]# cat [-AEnTv] Parameters: -A : Equivalent to the integration parameters of -vET, can list some Special characters ~ -E : Display the trailing line character $ at the end; -n : Print the line number; -T : Display the [tab] button as ^I; -v : List some special characters that cannot be seen tac< Br>

Starting from the last line, you can see that tac is the reverse write of cat! When nl is displayed, the line number is output!

touch

Create an empty file and revise a file date to current (mtime and atime) [root@linux ~]# touch [-acdmt] File Parameters: -a : Only modify access time; -c : only modify the time, not create a file; -d: can be followed by the date, you can also use --date="date or time" -m : modify mtime only; -t : back Can be connected to time, the format is [YYMMDDhhmm]

vi

vi file2 ( vi is the new file file2) (press i to enter the insert state, insert mode, press Esc to exit the insert mode In the insert mode, press dd to delete the current line of the cursor, press x to delete the current word, press j, n, l to move the cursor) :wq (Save and exit) :q! (Do not save and exit)

more One page at a time Display file contents Space (space): represents a page down; Enter: represents a downward line "row"; /string: represents the search for the contents of the content, down "string"; : f : Immediately display the file name and the number of lines currently displayed;

q : The delegate immediately leaves more and no longer displays the file. Rong.

clear Purpose: Clear the screen. How to use: Enter clear on the console.

write Access: All users Usage: write user [ttyname] Description: Send message to other users Count: user: User account to prepare message ttyname: If the user has two at the same time The above tty connection, you can choose the appropriate tty message. Example: Send a message to Rollaend, then there is only one connection in the gallery: write Rollaend

sleep Permission: All users Usage: sleep [--help] [--version] number[smhd]

Description: sleep can be used to delay the current action for a period of time. Parameter description: --help: display auxiliary message --version: display version number number : length of time, can be followed by s, m, h or d where s is seconds, m is minutes, h is hours, and d is the number of days Example: Display the current time after 1 minute delay, then display the time again: date; sleep 1m; Date

reboot

Restart the command, no need to say more.

halt Shutdown command, needless to say.

Copyright © Windows knowledge All Rights Reserved