Linux Command Line Guide

Commands dealing with managing files, directories, compressing and extracting, encrypting, etc…

…can be reviewed in my (THEAARBS) ranger rc.conf file.

Extract commands can be reviewed in my (THEAARBS) extract script.

Secure Shell

Run command [c] as a user [u] on host [h]

ssh [u]@[h] [c]

Run GUI command on host [h] as user [u]

ssh -f -Y [u]@[h] xeyes

Forward connections to host [h]:8080

ssh -g -l 8080:localhost:80 root@[h]

Forward connections from host [h]:1434 to imap

ssh -R 1434:imap:143 root@[h]

Install user [u] public key in host [h] avoiding password requirement at login

ssh -copy-id [u]@[h]

Copy (with permissions) to user [u]’s home directory on the host @[h]

scp -p -r [u]@[h]: [file] [dir]/

Resize Disk

Resize the physical volume to match the size of the partition (sda2 in this example)

pvresize /dev/sda2

Resize the logical volume to use the new space available

lvresize /dev/mapper/distro-path /dev/sda2

Resize the file system

resize2fs /dev/mapper/distro-path

If the last command gets an error, you can try xfs_growfs instead.

Package Management

Install from source

./configure make

Install from .deb package

dpkg -i filename.deb

Install from .rpm package

rpm -Uvh filename.rpm

Install a pacman package

pacman -U filename.tar.pkg.gz

Remove a pacman package and unneeded dependencies

pacman -Rs [package]

Clear pacman cache, force update

pacman -Scc
pacman -Syyu

Refresh pacman keys

pacman-key --refresh-keys

Remove all packages but base group

pacman -R $(comm -23 <(pacman -Qq | sort) <((for i in $(pacman -Qqg base); do pactree -ul "$i"; done) | sort -u))

File Permissions

Change permissions of file to [octal]

chmod \[octal\] \[filename\]

Change permissions of file to rwx for all

chmod 777 filename

Change permissions to rwx for the owner, rw for group and world

chmod 755

System Commands

Show the current date and time

date

Print current date and who’s online

date;who

Set timezone

timedatectl set-timezone America/Chicago

Show the system’s current uptime

uptime

Display a list of online users

w

View your login name

whoami

Show kernel information

uname -a

Show CPU information

cat /proc/cpuinfo

Show memory information

cat /proc/meminfo

Display disk usage

df

Display directory space usage

du

Show memory and swap usage

free

Show possible locations for [app]

whereis [app]

Display which [app] will be run by default

which [app]

Linux Swap File

/etc/dphys-swapfile

Restart swap service

/etc/init.d/dphys-swapfile stop
/etc/init.d/dphys-swapfile start

MYSQL

mysql -u root -p[root_password] [database_name] > dumpfilename.sql
mysql -u root -p[root_password] [database_name] < dumpfilename.sql

Others

Write ISO image to drive

sudo dd bs=512M if=file.iso of=/dev/sdX