Directory Information Viewing#
Directory Viewing Command#
Syntax:
ls [-alrtAFR] [name...]
Parameters:
- -a Display all files and directories (including hidden files starting with .)
- -d Only list directories (do not recursively list files in directories).
- -l Display file and directory information in long format, including permissions, owner, size, creation time, etc.
- -r Display files and directories in reverse order.
- -t Sort by modification time, with the newest files at the top.
- -A Same as -a, but does not list "." (current directory) and ".." (parent directory)
- -F Append a symbol to the listed file name; for example, "*" for executable files, "/" for directories
- -R Recursively display all files and subdirectories in a directory.
Example:
ls -l
Output:
total 12
drwxr-xr-x 2 user user 4096 Jun 23 09:30 Documents
drwxr-xr-x 2 user user 4096 Jun 23 09:30 Pictures
drwxr-xr-x 2 user user 4096 Jun 23 09:30 Videos
-rw-r--r-- 1 user user 0 Jun 23 09:30 file1.txt
Directory Change Command#
Syntax:
cd [dirName]
Parameters:
-
dirName The target directory to switch to.
-
~ Jump to your own home directory
-
../.. Up two levels
Example:
cd /home/user/Documents
Current Path Display Command#
Syntax:
pwd
Example:
pwd
Output:
/home/user/Documents
System Information Viewing Command#
Syntax:
uname
Example:
uname
Output:
Linux
Clear Screen Command#
Syntax:
clear
Example:
clear
Display File Content Command#
Syntax:
cat [file...]
Parameters:
- file The file to display the content of.
Example:
cat file1.txt
Output:
Hello, world!
Switch User Identity Command#
Syntax:
sudo [command]
Parameters:
- command The command to be executed with administrator privileges.
Example:
sudo apt-get update
File Copy Command#
Syntax:
cp [option] source destination
Parameters:
-
-i, --interactive Prompt for confirmation before overwriting files.
-
-v, --verbose Display detailed information during the copy process.
-
source The source file or directory to be copied.
-
destination The destination file or directory.
Example:
cp file1.txt file2.txt
Switch User Command#
Syntax:
su [user]
Parameters:
- user The user to switch to.
Example:
su user2
File Move Command#
Syntax:
mv [option] source destination
Parameters:
-
-i, --interactive Prompt for confirmation before overwriting files.
-
-v, --verbose Display detailed information during the move process.
-
source The source file or directory to be moved.
-
destination The destination file or directory.
Example:
mv file1.txt /home/user/Documents
Create Folder Command#
Syntax:
mkdir [option] directory...
Parameters:
-
-p, --parents Create parent directories if they do not exist.
-
directory The directory to be created.
Example:
mkdir documents
Create File Command#
Syntax:
touch [option] file...
Parameters:
-
-a, --time=atime Change the access time.
-
-c, --no-create Do not create a new file.
-
-m, --time=mtime Change the modification time.
-
-r, --reference=FILE Use the time information of the specified file.
-
file The file to be created.
Example:
touch file1.txt
Delete Command#
Syntax:
rm [option] file...
Parameters:
-
-f, --force Ignore nonexistent files and do not display warnings.
-
-i, --interactive Prompt for confirmation.
-
-r, -R, --recursive Recursively delete directories and their contents.
-
file The file or directory to be deleted.
Example:
rm file1.txt
Directory Delete Command#
Syntax:
rmdir [option] directory...
Parameters:
-
-p, --parents Remove parent directories if they are empty.
-
directory The directory to be deleted.
Example:
rmdir documents
Display Network Configuration Information Command#
Syntax:
ifconfig
Example:
ifconfig
Output:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::c6e9:84ff:fe87:6835 prefixlen 64 scopeid 0x20<link>
ether c4:e9:84:87:68:35 txqueuelen 1000 (Ethernet)
RX packets 45574 bytes 33661624 (33.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23257 bytes 2469127 (2.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Reboot Command#
Syntax:
reboot
Example:
reboot
Shutdown Command#
Syntax:
poweroff
Example:
shell
poweroff
System Help Command#
Syntax:
man [command]
Parameters:
- command The command to view the help for.
Example:
man ls
Data Synchronization to Disk Command#
Syntax:
sync
Example:
sync
Find File Command#
Syntax:
find [path...] [expression]
Parameters:
- path The path to search.
- expression The expression to match.
Example:
find /home/user -name "*.txt"
Output:
/home/user/Documents/file1.txt
/home/user/Documents/file2.txt
Find Content Command#
Syntax:
grep [option] pattern [file...]
Parameters:
-
-i, --ignore-case Ignore case.
-
-r, --recursive Recursively search files in directories.
-
-l, --files-with-matches Only display file names that contain matches.
-
pattern The pattern to search for.
-
file The file to search.
Example:
grep "Hello" file1.txt
Output:
Hello, world!
Folder Size Command#
Syntax:
du [option] [directory...]
Parameters:
-
-s, --summarize Only display total size.
-
-h, --human-readable Display size in human-readable format.
-
directory The directory to check the size of.
Example:
du -sh /home/user/Documents
Output:
4.0K /home/user/Documents
Disk Space Check Command#
Syntax:
df [option] [file...]
Parameters:
-
-h, --human-readable Display size in human-readable format.
-
file The file to check the space of.
Example:
df -h
Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 50G 50G 50% /
Open a File with gedit Command#
Syntax:
gedit [file...]
Parameters:
- file: The file to open.
Example:
gedit file1.txt
Current System Process Viewing Command#
Syntax:
ps [option]
Parameters:
- -a, --all: Display all processes, including those of other users.
- -u, --user=USER: Only display processes of the specified user.
- -x, --deselect: Do not display processes related to the terminal.
- -e: Equivalent to -A, display all processes.
- -f: Display detailed process information.
- -l: Display process information in long format.
- -p PID: Only display the specified PID process.
- -U, --userlist=USERLIST: Display processes of the specified user list.
Example:
ps -ef
Output:
UID
PID PPID C STIME TTY TIME CMD
root 1 0 0 09:30 ? 00:00:01 /sbin/init
root 2 0 0 09:30 ? 00:00:00 [kthreadd]
root 3 2 0 09:30 ? 00:00:00 [rcu_gp]
...
Real-Time Process Status Viewing Command#
Syntax:
top
Example:
top
File Type Viewing Command#
Syntax:
file [file...]
Parameters:
- file: The file to view the type of.
Example:
file file1.txt
Output:
file1.txt: ASCII text
This article is synchronized and updated to xLog by Mix Space
The original link is https://api.xn--i2r.cc/posts/Linux-Study/LS1