Play Linux Series Linux Basic Command

Even if you fall, you have to know how to grab a handful of sand in your hand.

With the gradual deepening of the exploration of security technology, I deeply understand the importance of mastering the Linux system for security research. To master the Linux system, you must first learn some common Linux commands, then master some common Linux tools, and finally understand the Linux kernel. Therefore, this article is the first of the series, mainly used to record and share some common and basic Linux commands.

Command help

The meaning of the parsing command (whatis, info)

1
2
Whatis whoami parses the meaning of the command
Info whoami detailed analysis of the meaning of the command

Find the installation path of the command (which, whereis)

1
2
Which whoami finds the location of the command
Whereis whoami looking for the location of the program

Directory Management

Catalog View (ls)

View directory structure

1
tree

View the size of all subfolders in the current directory after sorting

1
du -sh `ls` | black

View the number of files in the directory

1
find ./ | wc -l

Sort by time, display directory entries as a list

1
ls -lrt

Add an id number to the front of each file

1
ls | cat -n

Show readable file size:

1
ll -h

File directory permissions (chmod, chown)

1
2
3
4
Change the owner of the file chown
Change file read, write, execute, etc. chmod
Recursive subdirectory modification: chown -R tuxapp source/
Increase script executable permissions: chmod a+x myscript

File Management

File creation and deletion (touch, echo, rm -f)

Delete log file

1
Rm *log (equivalent: $find ./ -name "*log" -exec rm {} ;)

File View (du -sh)

View file size

1
Du -sh filename

Number of statistics file lines

1
wc -l test.txt

File content view (cat, head, tail)

Display line number at the same time

1
2
3
4
```
Dynamically view the contents of the file:
```bash
Tail -f filename #When there is content written to the file and then output

Positively reverse view file contents

1
2
Head -1 filename # Line 1 content
Tail -5 filename # Countdown 5 lines of content

JSON formatted output (jq)

1
cat test.json | jq

You can also use the python module:

1
cat test.json | python -m json.tool

File Search (find)

Linux to copy a specific suffix file (maintain directory structure):

1
tar cvf my_txt_files.tar `find . -type f -name "*.jsp*"`

Recursively the current directory and subdirectories and delete all .log files

1
find ./ -name "*.log" -exec rm {} \;

Negative parameters find all non-txt text

1
find . ! -name "*.txt" -print

Search by type

1
Find . -type d -print //List all directories only

All files that have been visited in the last 7 days

1
find . -atime -7 -type f -print

File Content Search (grep)

View the IP address of the successful login ssh:

1
centos

Recursive directory search returns the text content with the line number of the class string

1
grep "class" . -R -n

Non-matching (-v)

1
Ps -ef | grep -v "python" #match except python process

File content sorting (sort)

  • -n sort by number VS -d sort by lexicographic order
  • -r reverse ordering
  • -k N specifies sorting by column N
1
2
black-no. 1 data.txt
Sort -bd data // ignore leading whitespace characters like spaces

Eliminate duplicate lines (uniq)

Eliminate duplicate rows

1
sort unsort.txt | uniq

Count the number of times each line appears in the file

1
sort unsort.txt | uniq -c

Find duplicate rows

1
sort unsort.txt | uniq -d

Disk Management

View disk space utilization size

1
df -h

Mount the USB flash drive

1
2
3
4
Fdisk -l View U disk path
Mount /dev/sdb4 /mnt mount U disk
Cd /mnt enter U disk
Umount /mnt Exit U disk

Process Management

Kill python related processes

1
2
3
ps -ef | grep python | cut -d ' ' -f 2 | xargs kill
or
Pkill -9 python #-9 means forced deletion, pkill matches by process name

View process

1
ps -ef | less

Check the process status occupied by the port:

1
lsof -i:3306

Network Management

View network connections

1
netstat -an | less

View network routing

1
route -n

View only ip information

1
ifconfig | grep inet

System Management

View system digits

1
getconf LONG_BIT

View system version

1
lsb_release -a

View the hosts file

1
cat /etc/hosts

View the number of CPU cores

1
cat /proc/cpuinfo | grep processor | wc -l

View system information

1
2
3
4
5
6
7
8
uname -a
Uname -m shows the processor architecture of the machine
Uname -r shows the kernel version being used
Cat /proc/cpuinfo displays CPUinfo information
Cat /proc/meminfo Verify memory usage
Cat /proc/version shows the version of the kernel
Cat /proc/net/dev shows network adapters and statistics
Cat /proc/mounts shows the mounted file system

Performance Management

CPU (sar)

View CPU usage

1
has become -and

View CPU average load

1
sar -q 1 2

RAM

View memory usage

1
2
3
sar -r 1 2
or
free -m

Network Traffic Monitoring (iftop)

1
Sudo iftop -i eth1 -B #-i Specify the network card, -B is displayed in bytes, you can use -h to view help information

Server Performance View (htop)

The enhanced version of top is recommended for installation.

1
htop

Network Traffic (dstat)

Recommended Use.

1
dstat

Other content

Pipes and redirects (|, ||, &&, >, >>)

  • Batch command connection execution, use |
  • Use semicolons in series;
  • If the previous one succeeds, the next one is executed, otherwise it is not executed: &&
  • If the previous fails, the latter one executes: ||
  • >Overwrite the original content
  • >>Additional content after file

Redirect

1
2
Echo test > test.txt #overwrite the original content
Echo test >> test.txt #Additional content after file

Empty file

1
:> test.txt

Nohup output redirection

1
nohup python revice_true_link.py > ./log/true_link.log &

Bash shortcuts

  • Ctl-U deletes all characters from the cursor to the beginning of the line. Under some settings, delete all lines
  • Ctl-W deletes the character between the current cursor and the nearest space in the front
  • Ctl-H backspace, delete the character before the cursor
  • Ctl-R matches the closest file and then outputs
  • Ctl-a cursor moves to the beginning of the line
  • Ctl-e cursor moves to the end of the line

Download

Access remote resources, download resources

  • wget Function: Download remote files such as: http://www.xxx.com/1.txt
  • curl role: access the web page, return the package content

The program runs

  • watch running script -n seconds (execute once in a few seconds, without n to default to 2 seconds)
  • nohup program to run & (let the program run in the background, ignore all hang up signals)

Linux Learning Website

This article content reference

http://linuxtools-rst.readthedocs.io/zh_CN/latest/

Portal

[[Play linux system] Linux intranet penetration] (https://thief.one/2017/08/09/2/)
[[Play linux series] Vim use] (https://thief.one/2017/08/09/1/)
[[Play linux series] shell programming] (https://thief.one/2017/08/11/1/)

Note: The content of this article comes from the Internet, and some of it comes from personal experience summary; this article will continue to collect updates, welcome to add!

本文标题:Play Linux Series Linux Basic Command

文章作者:nmask

发布时间:2017年08月08日 - 20:08

最后更新:2019年07月11日 - 18:07

原始链接:https://thief.one/2017/08/08/1/en/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

nmask wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!

热门文章推荐: