Alright, fellow coder, you’ve made it this far and now you’re ready to conquer the command line like a true developer. Whether you're a terminal newbie or a seasoned keyboard warrior, mastering these commands will make you feel like a wizard casting spells (or, you know, just navigating files, but let's keep the magic alive).
Now, I promised you an epic list of essential command line commands—so here it is! A guide that's so essential, it'll make your IDE look like it's slacking off. So buckle up, grab your favorite energy drink, and let's dive into the world of terminal tricks. ๐ฉ✨
Navigation & File Management (Basics)
ls
– List files and directories in the current directory.cd [directory]
– Change to the specified directory.pwd
– Display the current working directory.mkdir [directory]
– Create a new directory.touch [file]
– Create an empty file.cp [source] [destination]
– Copy files or directories.mv [source] [destination]
– Move or rename files and directories.rm [file]
– Remove a file.rm -r [directory]
– Remove a directory and its contents.Viewing Files & Directories
cat [file]
– View the contents of a file.more [file]
– View the contents of a file one page at a time.less [file]
– View the file contents with backward navigation support.head [file]
– Display the first 10 lines of a file.tail [file]
– Display the last 10 lines of a file.tree
– Display directories and files in a tree-like structure.
Searching & Filtering
grep [pattern] [file]
– Search for a pattern in a file.find [directory] -name [file_name]
– Search for a file by name in a specific directory.locate [file_name]
– Quickly find a file by name (requireslocate
to be installed).wc [file]
– Count lines, words, and characters in a file.sort [file]
– Sort the lines of a file alphabetically.uniq
– Remove duplicate lines from sorted data.awk '{print $2}' [file]
– Extract and print specific columns from a file.
Networking & Connectivity
ping [host]
– Check connectivity to a host.curl [URL]
– Fetch a web page or API response.wget [URL]
– Download a file from the internet.ssh [user]@[host]
– Securely connect to a remote server.scp [file] [user]@[host]:[path]
– Copy a file between a local machine and a remote server.netstat
– View active network connections and listening ports.nslookup [domain]
– Get DNS information about a domain.
System Monitoring & Process Management
top
– Display a real-time view of system processes.htop
– Enhanced version oftop
(requires installation).ps
– View currently running processes.kill [PID]
– Terminate a process by its Process ID (PID).df -h
– Show disk space usage in a human-readable format.du -sh [directory]
– Show the total size of a directory.free -h
– Display memory usage.uptime
– Display the system uptime and load averages.
File Permissions & Ownership
chmod [permissions] [file]
– Change file permissions (e.g.,chmod 755 file
).chown [user]:[group] [file]
– Change the owner and group of a file.ls -l
– List files with detailed permissions and ownership information.
Archiving & Compression
tar -cvf [archive_name].tar [directory]
– Create a tar archive of a directory.tar -xvf [archive_name].tar
– Extract files from a tar archive.gzip [file]
– Compress a file using gzip.gunzip [file].gz
– Decompress a gzipped file.zip [archive_name].zip [file]
– Create a zip archive.unzip [archive_name].zip
– Extract files from a zip archive.
Advanced Commands
alias [name]='[command]'
– Create a shortcut for a command (e.g.,alias ll='ls -la'
).nano [file]
– Open a simple text editor in the terminal.vim [file]
– Open a powerful text editor (requires learning the commands).cron
– Schedule repetitive tasks using cron jobs.chmod +x [script.sh] && ./script.sh
– Make a script executable and run it.grep -r [pattern] [directory]
– Recursively search for a pattern in files.xargs
– Build and execute commands from standard input.diff [file1] [file2]
– Compare the differences between two files.
Version Control (Git)
git status
– Check the status of your Git repository.git add [file]
– Stage changes for commit.git commit -m "[message]"
– Commit changes with a message.git log
– View the commit history.git pull
– Fetch and merge changes from a remote repository.git push
– Push your changes to a remote repository.git branch
– List, create, or delete branches.git merge [branch_name]
– Merge another branch into the current branch.
Automation & Scripting
bash [script.sh]
– Execute a bash script.for i in {1..5}; do echo $i; done
– Loop through a range and execute commands.while true; do [command]; sleep 5; done
– Run a command in a loop with a delay.crontab -e
– Edit your cron jobs to schedule tasks.history
– View your command history.!!
– Re-run the last command.
Pro Tips
- Tab Completion: Use the Tab key to automatically complete file or command names.
- Command History: Press the up and down arrow keys to scroll through previous commands.
- Ctrl+C: Stop the currently running command.
- Ctrl+R: Search through your command history interactively.
And just like that, you’ve got yourself a one-stop shop for everything from file navigation to network troubleshooting, all served with a side of geeky humor. Use this cheat sheet well, and may your terminal never show "command not found" again!
Comments
Post a Comment