Fundamental command-line commands (0)
By Hongyu Xiao
Contact: hongyu.xiao@ou.edu
# NAVIGATION AND DIRECTORY MANAGEMENT
# Print Working Directory
pwd
# List directory contents
ls
ls -l # Detailed list view
ls -a # Show hidden files
ls -lh # Human-readable file sizes
# Change Directory
cd /path/to/directory
cd .. # Move up one directory
cd ~ # Go to home directory
# CREATE AND MANAGE FILES/DIRECTORIES
# Create directory
mkdir my_folder
# Create empty file
touch newfile.txt
# Remove file
rm file.txt
# Remove directory
rm -r directory_with_contents
# Copy files
cp source.txt destination.txt
# Move/Rename files
mv oldname.txt newname.txt
mv file.txt /path/to/directory/
# VIEW FILE CONTENTS
# Display file contents
cat filename.txt
# View file contents page by page
less filename.txt
# Show first/last lines
head filename.txt
tail filename.txt
# SYSTEM INFORMATION
# Current user
whoami
# System information
uname -a
# Disk space
df -h
# Memory usage
free -h
# PROCESS MANAGEMENT
# List running processes
ps aux
# Search for a process
ps aux | grep process_name
# PERMISSIONS
# Change file permissions
chmod 755 filename
# 755 means:
# 7 (owner): read, write, execute
# 5 (group): read, execute
# 5 (others): read, execute
# SEARCHING
# Find files
find /path -name "filename"
# Search file contents
grep "search_term" filename.txt
# COMPRESSED FILES
# Extract .tar.gz
tar -xzvf file.tar.gz
# Extract .zip
unzip file.zip
# Compress directory
tar -czvf archive.tar.gz directory_name
# COMMAND HELP
# Get help for a command
man command_name
command --help