Essential Linux Shell Commands: From Killing Processes to File Permissions
This guide walks through essential Linux shell commands covering process termination, system shutdown and reboot, echo usage, Vim editing shortcuts, file copying, moving, compression, searching with find and grep, as well as interpreting and modifying file permissions and ownership.
Introduction
Linux shell commands are fundamental tools for everyday tasks such as terminating processes, managing files, and inspecting system information. Below is a concise reference covering common commands and their usage.
Process Management
$ ps | grep xxx $ kill -9 xx
Using killall simplifies the operation:
$ killall -9 xxx
When killall is unavailable, combine adb and grep:
$ adb shell ps | grep speech | awk '{print $2}' > 1.txt $ cat 1.txt | xargs -n1 adb shell kill -9
Or in a single line:
$ adb shell ps | grep speech | awk '{print $2}' | xargs -n1 kill -9
Shutdown and Reboot
shutdown -h now # immediate shutdown
shutdown -h +10 # shutdown after 10 minutes
shutdown -h 12:00:00 # shutdown at 12:00
halt # equivalent to immediate shutdown
# Reboot
shutdown -r now
reboot # equivalent to immediate rebootEcho Command
root@ubuntu:~# a="hello,world"
root@ubuntu:~# echo a
a
root@ubuntu:~# echo &a
[1] 3091
a: command not found
[1]+ Done echo
root@ubuntu:~# echo $a
hello,worldVim Text Editor
vi somefile.4
# Modes:
# 1. Normal mode – accepts shortcuts, no editing.
# 2. Press i to enter Insert mode for editing.
# 3. Press Esc to return to Normal mode.
# 4. Press : to enter Command mode, then wq to save and quit.
# Common shortcuts (Normal mode):
a – insert after cursor
A – insert at end of line
I – insert at beginning of line
gg – go to first line
G – go to last line
dd – delete a line
3dd – delete three lines
yy – yank (copy) a line
3yy – yank three lines
p – paste
u – undo
v – visual character mode (y to copy, p to paste)
Ctrl+v – visual block mode
Shift+v – visual line mode
# Search and replace:
:set nu # show line numbers
:set nonu # hide line numbers
:/you # search for "you"
:s/sad/bbb # replace first "sad" on current line
:%s/sad/bbb # replace all "sad" in fileCopy, Delete, Move, Rename
cp somefile.1 /home/hadoop/
rm /home/hadoop/somefile.1
rm -f /home/hadoop/somefile.1
mv /home/hadoop/somefile.1 ../
mv a.txt b.txt # rename a.txt to b.txtCompression and Archiving
# gzip
gzip a.txt
# unzip
gunzip a.txt.gz
gzip -d a.txt.gz
# bzip2
bzip2 a
# bunzip2
bunzip2 a.bz2
bzip2 -d a.bz2
# tar
# create archive
tar -cvf bak.tar ./aaa
# append file to archive
tar -rvf bak.tar /etc/passwd
# extract archive
tar -xvf bak.tar
# create and compress
tar -zcvf a.tar.gz aaa/
# extract and decompress
tar -zxvf a.tar.gz
# extract to specific directory
tar -zxvf a.tar.gz -C /usr
# list contents
tar -ztvf a.tar.gz
# tar with bzip2
tar -jcvf a.tar.bz2
# extract bzip2 archive
tar -jxvf a.tar.bz2Find Command Examples
# locate executable
which ls
# locate command and manual
whereis ls
# find files by name
find / -name "hadooop*"
find / -name "hadooop*" -ls
# find and delete
find / -name "hadooop*" -ok rm {} \;
find / -name "hadooop*" -exec rm {} \;
# find files owned by user hadoop
find /usr -user hadoop -ls
# find directories owned by hadoop
find /home -user hadoop -type d -ls
# find files with permission 777
find / -perm -777 -type d -ls
# case‑insensitive search
find ./sound/ -iname ft56Q.c
# show command history
historyGrep Command Examples
# exact word match with line numbers
grep -wrn weiqifa ./sound/
# search excluding directories
grep -E "http" . -R --exclude-dir=./sound/
grep -E "http" . -R --exclude-dir={.git,res,bin}
# exclude extensions
grep -E "http" . -R --exclude=*.{java,js}
# basic usage
grep hadoop /etc/passwd
grep aaa ./*.txt
# extract 7th field after ':'
grep dsl /etc/passwd | cut -d: -f7
# lines not containing hadoop
grep -v hadoop /etc/passwd
# regex examples
grep 'hadoop' /etc/passwd
grep 'h.*p' /etc/passwd
grep '^hadoop' /etc/passwd
grep 'hadoop$' /etc/passwd
# exclude lines starting with '#'
grep -v '^#' a.txt | grep -v '^$'
# lines starting with h or r
grep '^[hr]' /etc/passwd
# lines not starting with h or r
grep '^[^hr]' /etc/passwd
# lines not starting with h‑r range
grep '^[^h-r]' /etc/passwdFile Permission Format
drwxr-xr-x # or 755 in numeric form
# d: directory, -: regular file, l: link
# r: read, w: write, x: execute
# Owner permissions: rwx
# Group permissions: r-x
# Others permissions: r-xChanging Permissions (chmod)
chmod g-rw haha.dat # remove group read/write
chmod o-rw haha.dat # remove others read/write
chmod u+x haha.dat # add execute for owner
chmod a-x haha.dat # remove execute for all
# numeric mode
chmod 664 haha.dat # rw-rw-r--
chmod -R 770 aaa/ # recursive change for directoryChanging Ownership (chown)
# only root can execute
chown angela aaa # change owner
chown :angela aaa # change group
chown angela:angela aaa/ # change both owner and groupDisk Usage
# directory size
du -sh sound/
# display disk space
df -hSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
