Professional Documents
Culture Documents
25 TIPS
©HM
HM LINUX SERIES 2020 25 TIPS
Table of Contents
1. sudo !! command...............................................................................................3
2. free -m command..............................................................................................4
3. touch command.................................................................................................5
4. killall command..................................................................................................6
5. last command....................................................................................................7
6. which command................................................................................................8
7. blkid command..................................................................................................9
8. systemd-analyze command.............................................................................10
9. df command.....................................................................................................12
10. tee command.................................................................................................13
11. lsof command................................................................................................14
12. fsck command................................................................................................15
13. chmod command...........................................................................................16
14. ps command..................................................................................................18
15. journal command..........................................................................................19
16. find command................................................................................................20
17. lspci command...............................................................................................21
18. curl ifconfig command...................................................................................22
19. ss command...................................................................................................23
20. Ctrl + L Key Combination...............................................................................24
21. ping command...............................................................................................25
22. uname command...........................................................................................26
23. rfkill command...............................................................................................27
24. systemctl command.......................................................................................28
25. dd command..................................................................................................29
©HM 2
HM LINUX SERIES 2020 25 TIPS
1. sudo !! command
If you forget to type sudo before a command that requires root privileges, just type
the following command:
$ sudo !!
Example:
$ apt update
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
$ sudo !!
More information about sudo on terminal
$ man sudo
$ sudo --help
Advanced information
Execute a specific command from the history using !n
If you’ve executed a command earlier, instead of re-typing it again, you can quickly execute it by
using the corresponding number of the command in the history.
For example, you executed 6 commands. To execute command #4, do the following. This will
display command #4 from the history, and execute it immediately.
$ !4
$ !-1
You can also press <Ctrl>-P (if you are in the default emacs mode) to get to the previous command.
If you’ve enabled vi style editing for the command line using ‘set -o vi’, use <Esc>-k to get to the
previous command.
©HM 3
HM LINUX SERIES 2020 25 TIPS
2. free -m command
To know the available amount of memory in megabytes, at any time, just type the
following command:
$ free -m
Example:$ free -m
©HM 4
HM LINUX SERIES 2020 25 TIPS
3. touch command
To create a new empty file, just type the following command:
$ touch nameofthefile
Example:$ touch overview.txt
The file overview.txt will be created in the default directory (/home/nameoftheuser)
You can verify this by typing $ ls.
More information about touch on terminal
$ man touch
$ touch --help
Advanced information
How to change access/modification time
Let's take an existing file as an example. Suppose you have created overview.txt last week.
By using the stat command:
$ stat overview.txt you will get the information about the timestamps: the last time the file was
accessed/opened by some command or application, the last time the file’s content was modified
and the last time the file’s attribute or content was changed. The attribute includes file
permissions, file ownership or file location.
Now, type $ touch overview.txt
By running $ stat overview.txt again, you will notice that the timestamps are updated to the
current time.
Similarly, if the requirement is to only change the modification time, use the -
m command line option.
$ touch -m [filename]
©HM 5
HM LINUX SERIES 2020 25 TIPS
4. killall command
When an app freezes, you can use the following command:
$ killall nameoftheapp
Example:$ killall firefox
killall sends a signal to all processes running any of the specified commands.
If no signal name is specified, SIGTERM is sent and the app will close immediately.
©HM 6
HM LINUX SERIES 2020 25 TIPS
5. last command
To know who logged in your computer, and when, simply use the following
command:
# last
Example using the ‘number of lines to display’ option
# last -2
©HM 7
HM LINUX SERIES 2020 25 TIPS
6. which command
To know where an app is located, use the following command:
$ which nameoftheapp
Example:
$ which blender
Because the app mega doesn’t exist, the output of the third line gives all the possible bin locations
for apps, on this computer. So, using which with the name of an app that doesn’t exist, is a trick to
find out all possible bin locations on the computer.
©HM 8
HM LINUX SERIES 2020 25 TIPS
7. blkid command
To list all the drives of a computer with their UUID, use the following command:
# blkid
Example:
# blkid
/dev/sdb1: UUID="6e0acfe3-81ed-4f9f-8ab5-0d65ba1f0ef2" TYPE="ext2"
/dev/sdc1: UUID="aa82d7bb-ab2b-4739-935f-fd8a5c9a6cb0" TYPE="ext2"
/dev/sda1: UUID="187171ab-c9b8-43ec-b0bb-77c736ca22e0" TYPE="ext4" LABEL="/home"
/dev/sda2: UUID="1a225baa-7027-4619-aaa5-900e24c1fdff" TYPE="swap"
/dev/sdb3: UUID="2a294b33-eb61-40a3-b3fc-ad6eaf7f156f" TYPE="ext2"
# blkid -p /dev/sda1
# blkid -p /dev/sda2
©HM 9
HM LINUX SERIES 2020 25 TIPS
8. systemd-analyze command
To check how fast your computer starts and find out why it boots slow, use the
following command:
$ systemd-analyze
Example:
$ systemd-analyze
$ systemd-analyze blame
©HM 10
HM LINUX SERIES 2020 25 TIPS
©HM 11
HM LINUX SERIES 2020 25 TIPS
9. df command
To check the available space on disks, in human readable format, use the following
command:
$ df -h
Example:
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 24G 2.5G 20G 11% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 1.6M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 2.0G 0 2.0G 0% /tmp
tmpfs 396M 0 396M 0% /run/user/1000
● -T : this causes a new column to be added to the output displaying the filesystem type.
● -t : this only shows specific file system types. Pass the -t option followed by the filesystem
type or types to be shown. This causes only the file system types to be shown. The -t
option accepts a list of types. Example: df -t ext4
● -x : this excludes specific file types. Pass the -x option followed by the filesystem type you
want to exclude. The -t option accepts a list of types. Example: df –x tmpfs
©HM 12
HM LINUX SERIES 2020 25 TIPS
©HM 13
HM LINUX SERIES 2020 25 TIPS
©HM 14
HM LINUX SERIES 2020 25 TIPS
©HM 15
HM LINUX SERIES 2020 25 TIPS
One way to use chmod is to provide the permissions you wish to give to the owner,
group, and others as a 3-digit number. The leftmost digit represents the owner. The
middle digit represents the group. The rightmost digit represents the others. The
digits you can use and what they represent are listed here:
• 0: No permission
• 1: Execute permission
• 2: Write permission
• 3: Write and execute permissions
• 4: Read permission
• 5: Read and execute permissions
• 6: Read and write permissions
• 7: Read, write and execute permissions
©HM 16
HM LINUX SERIES 2020 25 TIPS
©HM 17
HM LINUX SERIES 2020 25 TIPS
14. ps command
To view all the running processes , use the following command:
$ ps
To view all the running processes for an effective user ID or user name:
$ ps – user ID or user name
https://www.tecmint.com/ps-command-examples-for-linux-process-monitoring/
©HM 18
HM LINUX SERIES 2020 25 TIPS
To check the journal for a given subject and for a given period, use options.
Example:
# journalctl -b -u NetworkManager – since=”2020-04-16 06:00:00”
©HM 19
HM LINUX SERIES 2020 25 TIPS
If you don’t remember the name of the file but remember, for instance, that the file
is a .mp3 file with more than 10MB
https://www.tecmint.com/35-practical-examples-of-linux-find-command/
©HM 20
HM LINUX SERIES 2020 25 TIPS
©HM 21
HM LINUX SERIES 2020 25 TIPS
©HM 22
HM LINUX SERIES 2020 25 TIPS
19. ss command
To quickly check all ports in use, run the following command:
$ ss -a
Example: $ ss -a | less
https://www.howtoforge.com/linux-ss-command/
©HM 23
HM LINUX SERIES 2020 25 TIPS
Advanced information
Other key combinations to use with the terminal:
https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-
command-shell-for-ubuntu-debian-suse-redhat-linux-etc/
©HM 24
HM LINUX SERIES 2020 25 TIPS
$ ping archlinux.org – c 2
©HM 25
HM LINUX SERIES 2020 25 TIPS
©HM 26
HM LINUX SERIES 2020 25 TIPS
©HM 27
HM LINUX SERIES 2020 25 TIPS
TIP: to enable AND start a service, $ systemctl --now enable name of the
service.service (the “.service” is optional). You will be prompted to enter your
password.
©HM 28
HM LINUX SERIES 2020 25 TIPS
25. dd command
To quickly create a bootable flash-drive
$ sudo dd bs=4M if=/path/to/input.iso of=/dev/sd? oflag=sync
status=progress
Where:
input.iso is the input file (the .iso file you want to make bootable).
? is the letter of the USB flash drive you want to write on.
WARNING: run lsblk to view all drives in order to identify what ? Is the USB flash
drive you want to write on.
Example, assuming your USB flash drive is sdc and the iso file, archiso, is located in
your Downloads folder.
$ sudo dd bs=4M if ~/Downloads/archlinux-2020.05.01-x86_64.iso of=/dev/sdc
oflag=sync status=progress
©HM 29