This tool systematically organizes the most commonly used command line commands in the Linux operating system, covering file management, directory operations, permissions control and other core functions. By categorizing and summarizing with concise examples, it helps users quickly master the efficient operation of the command line environment.
File Operations: Including create, copy, move, delete and other basic file management commands.
Directory Management: Provides directory traversal, switching, statistics and other practical operation guidelines.
Permission Setting: Detailed explanation of user permissions and file attribute modification methods.
This tool uses standardized terminology to ensure that users with different language backgrounds can understand the functions of the commands and the scenarios in which they are used.
Command Code | Explanation |
---|---|
arch | Shows the processor architecture of the machine (1) |
uname -m | Display the processor architecture of the machine (2) |
uname -r | Display the kernel version in use |
dmidecode -q | Displays hardware system components -(SMBIOS / DMI) |
hdparm -i /dev/hda | List the architectural characteristics of a disk |
hdparm -tT /dev/sda | Perform a test read operation on a disk |
cat /proc/cpuinfo | Display information about CPU info |
cat /proc/interrupts | Display interrupts |
cat /proc/meminfo | Verify memory usage |
cat /proc/swaps | Shows which swaps are being used |
cat /proc/version | Show kernel version |
cat /proc/net/dev | Show network adapters and statistics |
cat /proc/mounts | Show loaded filesystems |
lspci -tv | List PCI devices |
lsusb -tv | Show USB devices |
date | Show system date |
cal 2007 | Show Calendar 2007 |
date 041217002007.00 | Setting the Date and Time - Month Day Hour Minute Year. Seconds |
clock -w | Save time changes to BIOS |
Command Code | Explanation |
---|---|
shutdown -h now | Shutdown System |
init 0 | Shut down the system |
telinit 0 | Shut down the system |
shutdown -h hours:minutes & | Shuts down the system at a predetermined time |
shutdown -c | Cancel scheduled system shutdown |
shutdown -r now | Reboot |
reboot | Reboot |
logout | Logout |
Command Code | Comment Description |
---|---|
cd /home | Enter'/ home' directory' |
cd .. | Return to the previous directory |
cd ../.. | Returns to the previous two levels of directories |
cd | Go to Personal Master Catalog |
cd ~user1 | Go to your personal home directory |
cd - | Return to the last directory |
pwd | Displaying the working path |
ls | Viewing files in a directory |
ls -F | Viewing files in a directory |
ls -l | Show file and directory details |
ls -a | Show hidden files |
ls *[0-9]* | Display file and directory names containing numbers |
tree | Displaying the tree structure of files and directories starting from the root directory |
lstree | Displaying the tree structure of files and directories starting from the root directory |
mkdir dir1 | Creates a directory called'dir1' directory' |
mkdir dir1 dir2 | Creates two directories at the same time |
mkdir -p /tmp/dir1/dir2 | Creating a directory tree |
rm -f file1 | Delete a file called'file1' file' |
rmdir dir1 | Delete a directory called'dir1' in a directory called' |
rm -rf dir1 | Delete a directory called'dir1' and delete its contents at the same time |
rm -rf dir1 dir2 | Delete two directories and their contents at the same time |
mv dir1 new_dir | Rename/move a directory |
cp file1 file2 | Copying a file |
cp dir0/g' example.txt | Replace multiple zeros with a single zero |
cat -n file1 | Marks the number of lines in a file |
cat example.txt | awk 'NR%2==1' | Delete all even lines in example.txt file |
echo a b c | awk '{print $1}' | View the first column of a line |
echo a b c | awk '{print $1,$3}' | View the first and third columns of a line |
paste file1 file2 | Merge the contents of two files or two columns |
paste -d '+' file1 file2 | Merge the contents of two files or two columns, separating them with the"+" Sort |
sort file1 file2 | Sort the contents of two files |
sort file1 file2 | uniq | Take out the union of two files( Keep only one copy of duplicate lines) |
sort file1 file2 | uniq -u | Delete the intersection and leave the rest of the rows. |
sort file1 file2 | uniq -d | Remove the intersection of two files( Leave only the files that exist in both files.) |
comm -1 file1 file2 | Compare the contents of two files and remove only'file1' Removes only the contents of the two files. |
comm -2 file1 file2 | Compare the contents of two files and remove only'file2' Included content |
comm -3 file1 file2 | Comparing the contents of two files removes only the parts that are common to both files. |
Command Code | Explanation |
---|---|
dos2unix filedos.txt fileunix.txt | Converts the format of a text file from MSDOS to UNIX. |
unix2dos fileunix.txt filedos.txt | Converts a text file from UNIX to MSDOS. |
recode ..HTML < page.txt > page.html | Convert a text file to html |
recode -l | more | Show all allowed conversion formats |
Command Code | Explanation |
---|---|
badblocks -v /dev/hda1 | Check for bad blocks on disk hda1 |
fsck /dev/hda1 | Repair/check integrity of linux file system on disk hda1 |
fsck.ext2 /dev/hda1 | Repair/check integrity of ext2 file system on disk hda1 |
e2fsck /dev/hda1 | Repair/check integrity of ext2 file system on disk hda1 |
e2fsck -j /dev/hda1 | Repair/check the integrity of the ext3 file system on disk hda1 |
fsck.ext3 /dev/hda1 | Repair/check the integrity of the ext3 file system on disk hda1 |
fsck.vfat /dev/hda1 | Repair/check the integrity of the fat file system on disk hda1 |
fsck.msdos /dev/hda1 | Repair/check the integrity of the dos file system on disk hda1 |
dosfsck /dev/hda1 | Repair/check the integrity of the dos file system on disk hda1 |
Command Code | Comment Explanation |
---|---|
mkfs /dev/hda1 | Creates a file system on the hda1 partition. |
mke2fs /dev/hda1 | Create a linux ext2 file system on hda1 partition |
mke2fs -j /dev/hda1 | Create a linux ext3 on partition hda1( logging) file system on the hda1 partition |
mkfs -t vfat 32 -F /dev/hda1 | Create a FAT32 file system |
fdformat -n /dev/fd0 | Format a floppy disk |
mkswap /dev/hda3 | Creating a swap filesystem |
Command Code | Explanation |
---|---|
mkswap /dev/hda3 | Creates a swap file system |
swapon /dev/hda3 | Enables a new swap file system |
swapon /dev/hda2 /dev/hdb3 | Enable two swap partitions |
Command Code | Note Explanation |
---|---|
dump -0aj -f /tmp/home0.bak /home | Makes a'/home' full backup of the directory |
dump -1aj -f /tmp/home0.bak /home | Makes an interactive backup of a'/home' interactive backup of a catalog |
restore -if /tmp/home0.bak | Restore an interactive backup |
rsync -rogpav --delete /home /tmp | Synchronize both directories |
rsync -rogpav -e ssh --delete /home ip_address:/tmp | rsync over an SSH channel |
rsync -az -e ssh --delete ip_addr:/home/public /home/local | Synchronize a remote directory to a local directory via ssh and compression |
rsync -az -e ssh --delete /home/local ip_addr:/home/public | Synchronize a local directory to a remote directory via ssh and compression |
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' | Perform a backup of a local disk on a remote host via ssh |
dd if=/dev/sda of=/tmp/file1 | Backup disk contents to a file |
tar -Puf backup.tar /home/user | Perform an interactive backup operation of the'/home/user' directory interactively |
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' | Copying the contents of a directory to a remote directory via ssh |
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' | Copy a local directory to a remote directory via ssh |
tar cf - . | (cd /tmp/backup ; tar xf - ) | Locally copy a directory to another location, preserving permissions and links. |
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents | Find and copy all files ending with'.txt' endings to another directory |
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 | Finds all files ending in'.log' endings and make a bzip package. |
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 | Do a copy of the MBR(Master Boot Record) contents to a floppy disk |
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 | Restore MBR contents from a backup that has been saved to a floppy diskette |
Command Code | Comment Explanation |
---|---|
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force | Empties the contents of a rewritable CD-ROM |
mkisofs /dev/cdrom > cd.iso | Creates a CD-ROM iso image file on a disk. |
mkisofs /dev/cdrom | gzip > cd_iso.gz | Creates a compressed CD-ROM iso image on disk. |
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd | Creates an iso image of a directory. |
cdrecord -v dev=/dev/cdrom cd.iso | Burn an ISO image file |
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - | Burn a compressed ISO image file |
mount -o loop cd.iso /mnt/iso | Mount an ISO image file |
cd-paranoia -B | Transcribe audio tracks from a CD-ROM to a wav file |
cd-paranoia -- "-3" | Transcribe tracks from a CD-ROM to a wav file (parameter -3) |
cdrecord --scanbus | Scan the bus to recognize scsi channels |
dd if=/dev/hdc | md5sum | Verify the md5sum encoding of a device, e.g. a CD-ROM. |
Command code | Notes |
---|---|
dhclient eth0 | Enables the 'eth0' network device in dhcp mode. |
ethtool eth0 | Display traffic statistics for network card 'eth0'. |
host www.example.com | Find hostnames to resolve names to IP addresses and mirrors |
hostname | Display hostnames |
ifconfig eth0 | Display the configuration of an Ethernet card |
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 | Controlling IP Addresses |
ifconfig eth0 promisc | Set 'eth0' to promiscuous mode for packet sniffing |
ifdown eth0 | Disabling an 'eth0' network device |
ifup eth0 | Enable an 'eth0' network device |
ip link show | Display the connection status of all network devices |
iwconfig eth1 | Display the configuration of a wireless card |
iwlist scan | Show wireless networks |
mii-tool eth0 | Display the connection status of 'eth0'. |
netstat -tup | Show all enabled network connections and their PIDs |
netstat -tup1 | Show all listening network services on the system and their PIDs. |
netstat -rn | Display the routing table, similar to the "route -n" command. |
nslookup www.example.com | Finds hostnames to resolve names and IP addresses and mirrors them. |
route -n | Display the routing table |
route add -net 0/0 gw IP Gateway | Controlling Predefined Gateways |
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 | Controls static routes to network '192.168.0.0/16'. |
route del 0/0 gw IP gateway | Delete static routes |
echo “1”> /proc/sys/net/ipv4/ip_foward | Activate IP Forwarding |
tcpdump tcp port 80 | Show all HTTP loops |
whois www.example.com | Lookup in Whois database |
Command Code | Note Explanation |
---|---|
mount -t smbfs -o username=user,password=pass | Mount a windows network share |
nbtscan ip addr | netbios name resolution |
nmblookup -A ip addr | netbios name resolution |
smbclient -L ip addr/hostname | Show remote share of a windows host |
smbget -Rr smb: | Download files from a windows host via smb like wget. |
Command Code | Explanation |
---|---|
iptables -t filter -L | Displays all links in the filter table |
iptables -t nae -L | Displays all links in the nat table |
iptables -t filter -F | Clears all rules based on the filter table |
iptables -t nat -F | Clears all rules based on the nat table |
iptables -t filter -X | Delete all links created by the user |
iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT | Allow telnet access |
iptables -t filter -A OUTPUT -p tcp --dport telnet -j DROP | Block telnet access |
iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT | Allow forwarding of POP3 connections on links |
iptables -t filter -A INPUT -j LOG --log-prefix | Log all packets blocked on the link |
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | Set up a PAT (Port Address Translation) to mask outgoing packets at eth0 |
iptables -t nat -A POSTROUTING -d 192.168.0.1 -p tcp -m tcp --dport 22-j DNAT --to-destination 10.0.0.2:22 | Divert packets destined for one host address to other hosts |
Command Code | Notes |
---|---|
free -m | List RAM status in megabytes |
kill -9 process id | Force a process to shut down and end it |
kill -1 process id | Force a process to reload its configuration |
last reboot | Show reboot history |
lsmod | List the status of kernel modules |
lsof -p process id | List a list of files opened by a process |
lsof /home/user1 | List open files in a given system path |
ps -eafw | List linux tasks |
ps -e -o pid,args --forest | List linux tasks in a hierarchical manner |
pstress | Display programs in a tree view |
smartctl -A /dev/hda | Monitor the reliability of hard disk devices by enabling SMART. |
smartctl -i /dev/hda | Check if SMART is enabled for a hard disk device. |
strace -c ls >/dev/null | List system calls made and received by a process |
strace -f -e open ls >/dev/null | List library calls |
tail /var/log/dmesg | Display internal events during kernel boot |
tail /val/log/messages | Show system events |
top | List the linux tasks that use the most CPU resources |
watch -nl ‘cat /proc/interrupts’ | List real-time interrupts |
Command Code | Notes |
---|---|
alias hh='history' | Set an alias for the command history. |
apropos ...keyword | Make a list of commands with program keywords, especially useful if you only know what the program does and you don't remember the commands. |
chsh | Changing shell commands |
chsh --list-shells | A nice command to know if you have to connect remotely to another machine. |
gpg -c filel | Encrypt a file with GNU Privacy Guard |
gpg filel.gpg | Decrypt a file with GNU Privacy Guard. |