← cd ~/posts
Mar 4, 2014 #linux #basics

Basic Linux/Unix Commands

# session & environment

tty reveals the current terminal
whoami reveals the current log-in user
which reveals where in the search path a program is located
echo $PATH prints to the screen; dumps the current path to STDOUT
set prints and optionally sets variables
clear clears the screen buffer
history reveals the command history
cd ~ user's $HOME directory in BASH
pwd print the current working directory
cd change directory to desired directory
su switch users — with no option, attempts to log in as root
w reveals connected terminals i.e 'pts/0…N' and/or 'tty1..N'

Tips: Up/Down arrows navigate command history. BASH supports tab completion — type unique characters and press TAB. In GNOME terminal: left button to block, right button (or Ctrl-Shift-V) to paste.

# files & directories

ls lists directories and files
cat concatenates files
mkdir creates a new directory
cp copies files
mv moves files
rm removes files/directories
touch create blank file / updates time-stamp
stat reveals statistics of files
find finds files using search patterns
alias returns / sets aliases for commands
file determines file type

# viewing text

more pagination — displays text one page at a time
less like more, e.g. less 1thousand.txt
head display opening lines of text files (first 10 lines)
tail display the closing lines of text
wc -l count words and optionally lines of text files
seq 1000 > 1thousand.txt echoes a sequence of numbers into a file

# networking

ping send ICMP ECHO_REQUEST to network hosts
ifconfig configure the kernel-resident network interfaces
netstat print network connections, routing tables, interface statistics and more
hostname show or set the system's host name
ssh OpenSSH SSH client (remote login program)
ftp Internet file transfer program
sftp secure file transfer program

# system & processes

uname -a returns OS, FQDN, kernel version and kernel compile date/time
top display Linux processes
ps report a snapshot of the current processes
mount mount a filesystem
df report file system disk space usage
swapon -s display summary of used swap devices
runlevel output previous and current runlevel
chroot run command or interactive shell with special root directory
init Upstart process management daemon
shutdown bring the system down
reboot reboot or stop the system (also: halt, poweroff)
login begin session on the system
passwd change user password
fdisk manipulate disk partition table

# permissions

chmod change file mode bits
chown change file owner and group

# editors & tools

vim Vi IMproved, a programmers text editor
nano Nano's ANOther editor, an enhanced free Pico clone
gedit text editor for the GNOME Desktop
bc an arbitrary precision calculator language
← back to all posts