Hey there! So, picture this: you're cruising through your digital landscape, toggling between Windows and its myriad of applications, when suddenly you remember that nifty little Linux environment you've got tucked away in your Windows Subsystem for Linux (WSL). You know, that handy tool that lets you dip your toes into the Linux pool without diving headfirst into the deep end of a dual-boot setup.
Now, if you're anything like me, WSL is a bit like that intriguing book you've been meaning to pick up but somehow always forget about until it catches your eye again. It's not that I don't appreciate its power and flexibility; it's just that my day-to-day routine tends to revolve more around the Windows ecosystem.
But every now and then, usually when I'm knee-deep in a project or troubleshooting some pesky compatibility issue, I find myself reaching for WSL like an old friend.
So, in the spirit of embracing the best of both worlds, I've put together a little cheat sheet of sorts - a handy reminder of some of the most useful and basic Linux commands that I've found myself reaching for time and time again. Whether you're navigating your file system, wrangling processes, or just poking around under the hood of your system, consider this your guide to unlocking the full potential of WSL (and maybe even picking up a few new tricks along the way). Let's dive in, shall we?
Navigating
Learn how to traverse through your file system like a pro with these essential commands for navigation.
$ pwd # Show current directory
$ ls # Directory listing
$ ls -l # Formatted listing (possible shorthand: "ll")
$ ls -la # Formatted listing and includes hidden files
$ cd # Change to home directory
$ cd dir # Change directory to "dir"
$ cd .. # Change to parent directory
$ cd ../dir # Change to "dir" in parent directory
$ mkdir dir # Create a directory "dir"
$ rm -r dir # Remove directories and their contents recursively
Files
From creating, copying, and moving files to viewing their contents, master the basics of file manipulation in Linux.
$ touch file # Create or update "file"
$ rm file # Remove "file"
$ rm -f file # Force remove "file"
$ cp file1 file2 # Copy "file1" to "file2"
$ mv file1 file2 # Rename "file1" to "file2"
$ mv file1 dir/file2 # Move "file1" to "dir/file2"
$ cat file # Output contents of "file"
$ cat > file # Write (replace) standard input into "file" (CTRL + D to write changes)
$ cat >> file # Write (append) standard input into "file" (CTRL + D to write changes)
$ tail -f file # Output contents of "file" as it grows
Processes
Take control of running processes with commands to manage and monitor them effectively, ensuring smooth system operation.
$ ps # Display currently active processes
$ ps aux # Detailed output
$ ps aux | grep man # Detailed output, only include processes with "man" in its description
$ kill pid # Kill process with id "pid"
$ killall proc # Kill all processes with "proc" in its description
System Info
Explore commands to gather key information about your system's hardware, software, and network configurations.
$ date # Show current date/time
$ uptime # How long the system have been running and mini stats
$ whoami # User that you are logged in as
$ w # Display who is online
$ cat /proc/cpuinfo # Display CPU info
$ cat /proc/meminfo # Display memory info
$ free # Display memory and swap usage
$ du # Display directory disk usage
$ du -sh # Display directory disk usage (summarize, human-readable)
$ df # Display disk usage
$ uname -a # Display kernel config
$ ip a # Display information on all the network interfaces
Compressing
Discover ways to compress and decompress files efficiently, saving space and streamlining data management tasks.
$ tar cf file.tar # Tar files into file.tar
$ tar xf file.tar # Untar into current directory
$ tar tf file.tar # Show contents of archive
options:
c - create archive
t - table of contents
x - extract
z - use zip/gzip
f - specify filename
j - bzip2 compression
w - ask for confirmation
k - do not overwrite
T - files from file
v - verbose
Permissions
Understand Linux file permissions and ownership, and learn how to modify them to control access and security.
$chmod octal file # Change permissions of file
4 - read (r)
2 - write (w)
1 - execute (x)
order: owner/group/world
$ chmod 777 # rwx for everyone
$ chmod 755 # rwx for owner, rx for group and world
Misc
Explore additional handy commands for various tasks, rounding out your Linux command repertoire.
$ grep pattern files # Search in files for pattern
$ grep -r pattern dir # Search for pattern recursively in dir
$ locate file # Find all instances of file
$ whereis app # Find possible locations of app
$ man command # Show manual page for command
Final thoughts
These are just a handful of commands I find essential to keep at arm's reach. I might update this list as I discover more useful ones, but for now, I'll leave it here. Hopefully, this short compilation proves as handy for you as it has for me!