Skip to content
/var/log/tienvv.blog
About meLinkedin

Linux commands

devops, scripting1011 min read

  • tee

tee : read from stdin and write to stdout as well as file(s)

df -h | tee disk_usage.txt

1Filesystem Size Used Avail Use% Mounted on
2dev 7.8G 0 7.8G 0% /dev
3run 7.9G 1.8M 7.9G 1% /run
4/dev/nvme0n1p3 212G 159G 43G 79% /
5tmpfs 7.9G 357M 7.5G 5% /dev/shm
6tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
7tmpfs 7.9G 15M 7.9G 1% /tmp
8/dev/nvme0n1p1 511M 107M 405M 21% /boot
9/dev/sda1 459G 165G 271G 38% /data
10tmpfs 1.6G 16K 1.6G 1% /run/user/120

Ouput also saved to the disk_usage.txt file

  • awk : manipulate text data

The file contents could look something like this:

1fristName lastName age city ID
2
3Thomas Shelby 30 Rio 400
4Omega Night 45 Ontario 600
5Wood Tinker 54 Lisbon N/A
6Giorgos Georgiou 35 London 300
7Timmy Turner 32 Berlin N/A

Print all

1awk '{print $0}' information.txt

Ouptut:

1fristName lastName age city ID
2
3Thomas Shelby 30 Rio 400
4Omega Night 45 Ontario 600
5Wood Tinker 54 Lisbon N/A
6Giorgos Georgiou 35 London 300
7Timmy Turner 32 Berlin N/A

Print first column

1awk '{print $1}' information.txt

Ouput:

1Thomas
2Omega
3Wood
4Giorgos
5Timmy

Print line start with O (regex)

1awk '/^O/' information.txt

Output:

1Omega Night 45 Ontario 600
  • head : print top N line from files

print lines between 10 and 20

1head -n 20 state.txt | tail -10
  • tail : print last N line from files

tail -f following logfile

  • less : showing part of file without loading entire file to memory, reduce using memory when accessing large text file

less -p "failure": start at first occurrence of pattern “failure” in the file.

less -N: show content with line number

  • touch : update modification time of file to current time, create file if not exist
  • cut: cutting out the sections from each line of files and writing the result to standard output
  • lsof: Listof Open Fileprovides a list of files that are opened

lsof -c Mysql : list all files opened by Mysql

lsof -u root : list all files opened by user root

lsof -u ^root : list all files opened by everyone except root

lsof -p PID : list all files opened by PID

  • ps: Process Status is used to list the currently running processes and their PIDs along with some other information depends on different options. It reads the process information from the virtual files in /proc file-system. /proc contains virtual files, this is the reason it’s referred as a virtual file system

ps -aux: view  processes owned by a user named "x"

  • netstat: Network Statistic

  • &``disown``nohup :

& puts the job in the background, that is, makes it block on attempting to read input, and makes the shell not wait for its completion.

disown removes the process from the shell's job control, but it still leaves it connected to the terminal. One of the results is that the shell won't send it a SIGHUP. Obviously, it can only be applied to background jobs, because you cannot enter it when a foreground job is running.

nohup disconnects the process from the terminal, redirects its output to nohup.out and shields it from SIGHUP. One of the effects (the naming one) is that the process won't receive any sent SIGHUP. It is completely independent from job control and could in principle be used also for foreground jobs (although that's not very useful).

© 2024 by /var/log/tienvv.blog. All rights reserved.
Theme inspired by LekoArts