DEV Community

Jiaju_Xie
Jiaju_Xie

Posted on

Linux Common Commands

Linux Common Commands — English Explanation

参考文档:菜鸟教程 https://www.runoob.com/w3cnote/linux-common-command-2.html

  1. ls

Meaning: list files and directories.

You use ls to see what is inside a folder. It can also show hidden files, file permissions, file size, and modification time.

Common options:

ls -a → show all files, including hidden ones

ls -l → show detailed information

ls -h → show file sizes in human-readable form

ls -t → sort by modification time

ls -S → sort by file size

Example:

ls -lhrt

This means:

-l detailed list

-h readable sizes

-r reverse order

-t sort by time

  1. cd

Meaning: change directory.

Used to move from one folder to another.

Examples:

cd /

Go to the root directory.

cd ~

Go to the home directory.

cd -

Go back to the previous directory.

  1. pwd

Meaning: print working directory.

It shows your current directory path.

Example:

pwd
pwd -P

Shows the real path, not the symbolic link path.

  1. mkdir

Meaning: make directory.

Used to create new folders.

Examples:

mkdir t

Create a folder named t.

mkdir -p /tmp/test/t1/t

Create nested directories at once.
-p means create parent directories if needed.

  1. rm

Meaning: remove files or directories.

Examples:

rm -i *.log

Delete .log files, but ask for confirmation first.

rm -rf test

Delete the test directory and everything inside it.

-r recursive

-f force

This command is powerful and dangerous.

  1. rmdir

Meaning: remove empty directories only.

Example:

rmdir -p parent/child/child11

Delete the last empty directory, and also remove parent directories if they become empty.

  1. mv

Meaning: move or rename files.

Examples:

mv test.log test1.txt

Rename test.log to test1.txt.

mv log1.txt log2.txt log3.txt /test3

Move multiple files into /test3.

  1. cp

Meaning: copy files or directories.

Examples:

cp -ai a.txt test

Copy a.txt to test, keep original time, and ask before overwriting.

cp -s a.txt link_a.txt

Create a symbolic link to a.txt.

  1. cat

Meaning: display file content, create files, or combine files.

Examples:

cat filename

Display the whole file.

cat > filename

Create a new file from keyboard input.

cat file1 file2 > file

Combine two files into one.

Also:

cat -n → show line numbers

cat -b → show line numbers only for non-empty lines

  1. more

Meaning: view a file page by page.

Useful when a file is too long for one screen.

Example:

more +3 text.txt

Start showing the file from line 3.

You can press:

Space → next page

b → previous page

q → quit

  1. less

Meaning: better file viewer than more.

It lets you scroll forward and backward more freely.

Examples:

less 1.log 2.log

Open multiple files.

Useful keys:

/text → search forward

?text → search backward

n → next match

N → previous match

Q → quit

  1. head

Meaning: show the beginning of a file.

Example:

head -n 20 1.log

Show the first 20 lines.

  1. tail

Meaning: show the end of a file.

Example:

tail -f ping.log

Continuously monitor new content added to a log file.

Very useful for watching logs in real time.

  1. which

Meaning: find the location of an executable command.

Example:

which ls

Shows where the ls command is located.

It only searches commands in the PATH.

  1. whereis

Meaning: find the binary file, source code, and manual page of a command.

Example:

whereis locate

Compared with which, whereis gives more related locations.

  1. locate

Meaning: quickly search for files by name using a database.

Example:

locate pwd

It is fast, but may miss very new files because it depends on a database that updates periodically.

  1. find

Meaning: search files and directories in the file system.

This is one of the most important Linux commands.

Examples:

find ./ -name '*.log'

Find all .log files in the current directory.

find /opt -perm 777

Find files with permission 777.

find . -type f -mtime +10 -exec rm -f {} \;

Find files older than 10 days and delete them.

find can search by:

name

type

size

time

owner

permissions

It can also run commands on the results using -exec.

  1. chmod

Meaning: change file permissions.

Linux permissions include:

r = read

w = write

x = execute

Examples:

chmod a+x t.log

Give execute permission to everyone.

chmod 751 t.log

Set permissions numerically:

owner = 7 = rwx

group = 5 = r-x

others = 1 = --x

  1. tar

Meaning: archive files, and often compress them.

Important idea:

archive = pack many files into one

compress = reduce file size

Examples:

tar -zcvf /tmp/etc.tar.gz /etc

Create a compressed archive of /etc.

tar -ztvf /tmp/etc.tar.gz

List contents of a compressed archive.

Common options:

-c create

-x extract

-t list contents

-f specify filename

-z gzip

-j bzip2

-v verbose

  1. chown

Meaning: change file owner and group.

Examples:

chown -c mail:mail log2012.log

Change the owner and group to mail.

chown -cR mail: test/

Recursively change ownership for a directory.

  1. df

Meaning: display disk space usage.

Example:

df -haT

Show all file systems, in readable format, with file system type.

Use this to check how much disk space is left.

  1. du

Meaning: show disk usage of files and directories.

Example:

du -ah scf/

Show the size of all files and subdirectories.

du -hc test/ scf/

Show sizes plus a total.

Difference:

df = disk free space of the whole filesystem

du = size used by specific files/folders

  1. ln

Meaning: create links.

Two types:

soft link (ln -s) = like a shortcut

hard link = another name for the same file data

Examples:

ln -sv source.log link.log

Create a symbolic link.

ln -v source.log link1.log

Create a hard link.

  1. date

Meaning: display or set the system date and time.

Examples:

date

Show current date and time.

date -d tomorrow +%Y%m%d

Show tomorrow’s date in YYYYMMDD format.

Useful for scripts.

  1. cal

Meaning: display a calendar.

Examples:

cal 9 2012

Show the calendar for September 2012.

cal -y 2013

Show the full calendar for 2013.

  1. grep

Meaning: search text by pattern.

This is one of the most useful commands in Linux.

Examples:

ps -ef | grep svn

Search for processes containing svn.

grep -lR '^grep' /tmp

Recursively find files in /tmp whose content starts with grep.

Useful options:

-i ignore case

-n show line numbers

-c count matches

-R recursive search

  1. wc

Meaning: count lines, words, and bytes.

Example:

wc text.txt

Shows:

number of lines

number of words

number of bytes

filename

cat test.txt | wc -l

Count lines in output.

  1. ps

Meaning: show current running processes.

Examples:

ps -ef

Show all processes in full format.

ps -aux | grep apache

Find the Apache process.

This command helps you inspect what programs are running.

  1. top

Meaning: dynamic process monitor.

It shows:

CPU usage

memory usage

running processes

system load

It updates in real time.

Useful interactive keys:

P sort by CPU

m sort by memory

c show full command line

h help

  1. kill

Meaning: send a signal to a process.

Example:

kill -9 PID

Forcefully stop a process.

-9 means SIGKILL, which cannot be ignored.

Safer default:

kill PID

This sends SIGTERM first.

  1. free

Meaning: show memory usage.

Examples:

free -m

Show memory usage in MB.

free -s 10

Refresh every 10 seconds.

Useful for checking RAM and swap usage.

Main idea of the whole article

This article is trying to teach basic Linux command-line operations.
It covers 4 major areas:

  1. File and directory operations

Examples:

ls

cd

pwd

mkdir

rm

mv

cp

  1. File viewing and searching

Examples:

cat

more

less

head

tail

grep

find

  1. System monitoring

Examples:

ps

top

free

df

du

  1. Permissions and archive management

Examples:

chmod

chown

tar

ln

A more natural English summary

You could describe this page like this:

This article introduces commonly used Linux commands for beginners. It explains how to navigate directories, manage files, search for content, check system resources, change file permissions, and handle processes. These commands are essential for daily Linux usage and system administration.

中文意思:

这篇文章向初学者介绍了常用的 Linux 命令,内容包括目录切换、文件管理、内容搜索、系统资源查看、权限修改以及进程管理。这些命令是日常使用 Linux 和进行系统管理的基础。

If you want to study this efficiently

I’d group them like this:

Must learn first

ls

cd

pwd

mkdir

rm

cp

mv

cat

Very practical next

grep

find

head

tail

less

For system monitoring

ps

top

df

du

free

For admin tasks

chmod

chown

kill

tar

Top comments (0)