build details

Show: section status errors & todos local changes recent changes last change in-page changes feedback controls

Useful Linux commands

Modified 2019-09-22 by Andrea Censi

A reference of useful Linux commands.

Getting help

Modified 2019-09-22 by Andrea Censi

man

Modified 2019-09-22 by Andrea Censi

This is an interface to the on-line reference manuals. Whenever you meet some unfamiliar commands, try use man certain_command before Googling. You will find it extremely clear, useful and self-contained.

Looking around

Modified 2019-09-22 by Andrea Censi

cd

Modified 2019-09-22 by Andrea Censi

Go to the directory you want. If you just use:

$ cd

then you will go to your home directory, i.e., /home/user/

To go up one directory use:

$ cd ..

ls

Modified 2019-09-22 by Andrea Censi

List all the files and documents in the current directory. From ~/.bashrc, we know some commonly used alias. See more by man ls.

la for ls -a which will list out all files and documents including the hidden ones(whose name starts with a dot).

ll for ls -l which will display Unix file types, permissions, number of hard links, owner, group, size, last-modified date and filename.

Showing authority

Modified 2019-09-22 by Andrea Censi

sudo

Modified 2019-09-22 by Andrea Censi

Whenever you want to modify system files, you will need sudo. Commonly touched system files including /etc, /opt and so on. Since most of you have followed the guideline to use passwordless sudo, I would recommend that make sure what you are doing with sudo before you execute the command, otherwise you may need to reinstall the system.

visudo

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (12 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

Changing things around

Modified 2019-09-22 by Andrea Censi

cp

Modified 2019-09-22 by Andrea Censi

cp fileA directoryB will copy the file A to directory B. See more by executing man cp.

mv

Modified 2019-09-22 by Andrea Censi

mv fileA directoryB will move the file A to directory B. See more by executing man mv. This command can be used to rename a file, to do so execute: mv fileA fileB

mkdir

Modified 2019-09-22 by Andrea Censi

Make new directory. See more by man mkdir.

rm

Modified 2019-09-22 by Andrea Censi

Remove certain file. rm -r will also remove directories. More in man rm.

touch

Modified 2019-09-22 by Andrea Censi

Update the access and modification times of the input file to current time. See more by man touch. It can be used to create empty documents, for example: touch duckie.txt Will create an empty text file.

Restarting

Modified 2019-09-22 by Andrea Censi

reboot

Modified 2019-09-22 by Andrea Censi

This command must be executed as root. sudo required. This will reboot your laptop or Raspberry Pi. See more by man reboot.

shutdown

Modified 2019-09-22 by Andrea Censi

This command requires sudo. You can set a countdown to shutdown you machine. More by man shutdown.

UNIX processes

Modified 2019-09-22 by Andrea Censi

cat

Modified 2019-09-22 by Andrea Censi

Cat some file will return you the content. More in man cat.

tee

Modified 2019-09-22 by Andrea Censi

Read from standard input and write to standard output and files. More on man tee.

truncate

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (13 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

Linux disks and files

Modified 2019-09-22 by Andrea Censi

fdisk

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (14 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

mount

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (15 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

umount

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (16 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

losetup

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (17 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

gparted

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (18 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

dd

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (19 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

sync

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (20 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

df

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (21 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

Users and permissions

Modified 2019-09-22 by Andrea Censi

passwd

Modified 2019-09-22 by Andrea Censi

Update password of the current user. Old password needed.

chmod

Modified 2019-09-22 by Andrea Censi

chmod changes permission to a file or a directory. To make a file executable run:

$ sudo chmod +x FILE

groups

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (22 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

adduser

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (23 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

useradd

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (24 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

Downloading

Modified 2019-09-22 by Andrea Censi

curl

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (25 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

wget

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (26 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

Measuring CPU and IO usage

Modified 2019-09-22 by Andrea Censi

Measuring CPU usage using htop

Modified 2019-09-22 by Andrea Censi

You can use htop to monitor CPU usage.

$ sudo apt install htop

TODO: put screenshot

previous task next (27 of 40) index
task

The following was marked as "todo".

TODO: put screenshot

Location not known more precisely.

Created by function n/a in module n/a.

Measuring I/O usage using iotop

Modified 2019-09-22 by Andrea Censi

Install using:

$ sudo apt install iotop

TODO: put screenshot

previous task next (28 of 40) index
task

The following was marked as "todo".

TODO: put screenshot

Location not known more precisely.

Created by function n/a in module n/a.

Networking utils

Modified 2019-09-22 by Andrea Censi

hostname

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (29 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

ping: are you there?

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (30 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.

ifconfig

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (31 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.
$ ifconfig

Wireless networking

Modified 2019-09-22 by Andrea Censi

iwconfig

Modified 2019-09-22 by Andrea Censi

iwlist

Modified 2019-09-22 by Andrea Censi

iwlist is useful to understand the status of the Wifi networks.

For example, to get a list of wifi networks, use:

$ sudo iwlist interface scan | grep SSID

To check whether the interface support 5 GHz channels, use:

$ sudo iwlist interface freq

Example output:

wlx74da38c9caa0  20 channels in total; available frequencies :
  Channel 01 : 2.412 GHz
  Channel 02 : 2.417 GHz
  Channel 03 : 2.422 GHz
  Channel 04 : 2.427 GHz
  Channel 05 : 2.432 GHz
  Channel 06 : 2.437 GHz
  Channel 07 : 2.442 GHz
  Channel 08 : 2.447 GHz
  Channel 09 : 2.452 GHz
  Channel 10 : 2.457 GHz
  Channel 11 : 2.462 GHz
  Channel 36 : 5.18 GHz
  Channel 40 : 5.2 GHz
  Channel 44 : 5.22 GHz
  Channel 48 : 5.24 GHz
  Channel 149 : 5.745 GHz
  Channel 153 : 5.765 GHz
  Channel 157 : 5.785 GHz
  Channel 161 : 5.805 GHz
  Channel 165 : 5.825 GHz
  Current Frequency:2.437 GHz (Channel 6)

Note that in this example only some 5Ghz channels are supported (36, 40, 44, 48, 149, 153, 157, 161, 165); for example, channel 38, 42, 50 are not supported. This means that you need to set up the router not to use those channels.

Moving files between computers

Modified 2019-09-22 by Andrea Censi

scp

Modified 2019-09-22 by Andrea Censi

The Secure Copy (scp) copies files from different hosts using ssh for data transfer.

Download a file with SCP

Modified 2019-09-22 by Andrea Censi

To download a file named file.txt which is on hostname use this command:

laptop $ scp hostname:/path/to/file.txt /path/where/you/whish/.

to download file.txt to /path/where/you/whish/. If you want to download in the current directory simply use:

laptop $ scp hostname:/path/to/file.txt .

rsync

Modified 2019-09-22 by Andrea Censi

TODO: to write

previous task next (32 of 40) index
task

The following was marked as "todo".

TODO: to write

Location not known more precisely.

Created by function n/a in module n/a.