Show the current logged-in user.
whoami
Show the User details.
finger <username>
Display the current date and time.
date
Command | Description |
---|---|
pwd | Print working directory |
ls | List directory contents |
ls -a | List all contents including hidden files |
ls -l | List contents with detailed information |
cd | Change to home directory |
cd [dirname] | Change to specific directory |
cd .. | Change to parent directory |
find [dirtosearch] -name [filename] | Find a file or directory |
Open files or directories in GUI.
- Mac:
open [dirname]
- Windows:
start [dirname]
- Linux:
xdg-open [dirname]
Command | Description |
---|---|
mkdir [dirname] | Make directory |
touch [filename] | Create file |
rm [filename] | Remove file |
rm -r [dirname] | Remove directory |
cp [filename] [dirname] | Copy file |
mv [filename] [dirname] | Move file |
mv [filename] [filename] | Rename file or directory |
Create a new file with output.
> [filename]
View, create, or append files.
cat [filename]
cat > [filename]
cat >> [filename]
View file contents with scrolling.
less [filename]
Exit with q
.
Display messages or create/write files.
echo "Hello World"
echo "Hello World" > [filename]
echo "Hello World" >> [filename]
Edit files with Nano.
nano [filename]
Exit with Ctrl + X
, then Y
to save or N
to discard.
Display the beginning or end of files.
head [filename]
head -n 5 [filename]
tail [filename]
tail -n 5 [filename]
Search for patterns in files.
grep [searchterm] [filename]
Locate files and directories.
find [dirname] -name [filename]
find . -empty
find . -name "file-*" -delete
Redirect output to another command or file.
find . -name "file-0*" > output.txt
Create shortcuts to files or directories.
ln -s [filename] [symlinkname]
rm [symlinkname]
For Windows:
mklink [symlinkname] [filename]
Compress or extract files with tar.
Command | Description |
---|---|
tar czvf [dirname].tar.gz [dirname] | Create tarball |
tar tzvf [dirname] | See contents of tarball |
tar xzvf [dirname].tar.gz | Extract tarball |
Command | Description |
---|---|
ifconfig | Display network configuration |
ip addr show | Display IP addresses and network interfaces |
ping [hostname] | Check connectivity to a host |
traceroute [hostname] | Trace the route packets take to a network host |
nslookup [hostname] | Query the DNS for information about a domain |
dig [domain] | Detailed DNS query |
netstat | Network statistics |
curl [url] | Transfer data from or to a server |
wget [url] | Download files from the web |
Command | Description |
---|---|
top | Display active processes |
htop | Interactive process viewer |
ps | Display information about active processes |
df | Report file system disk space usage |
du | Estimate file space usage |
free | Display memory usage |
uname -a | Display system information |
Command | Description |
---|---|
df -h | Show disk usage in human-readable format |
du -sh [dirname] | Show disk usage for a directory |
du -shl * | Show disk usage for all items in a directory |
Command | Description |
---|---|
apt-get update | Update package lists (Debian/Ubuntu) |
apt-get upgrade | Upgrade installed packages (Debian/Ubuntu) |
yum update | Update packages (RedHat/CentOS) |
yum upgrade | Upgrade packages (RedHat/CentOS) |
Command | Description |
---|---|
uname -r | Show kernel version |
lsb_release -a | Show Linux distribution information |
hostnamectl | Query and change the system hostname |
Command | Description |
---|---|
chmod [options] [filename] | Change file mode (permissions) |
chown [owner]:[group] [file] | Change file owner and group |
sudo [command] | Execute a command as another user |
getfacl | Easy Permission Read(File Access Control) |