Useful bash commands
Here’s a list of essential Bash commands that are incredibly useful for everyday tasks and more complex scripting. Whether you’re a beginner or advanced user, these will come in handy:
1. Navigation & File Management
pwd— Show the current directory path.ls— List files and directories.cd— Change directory.mkdir— Create a new directory.rm— Remove files or directories (use with caution).cp— Copy files or directories.mv— Move or rename files and directories.touch— Create an empty file.find— Search for files in a directory hierarchy. Example:find /path -name "*.txt"
2. Viewing & Editing Files
cat— Concatenate and display file contents.less— View large files one page at a time.headandtail— Display the beginning or end of a file.nanoorvim— Simple text editors to edit files in the terminal.
3. File Permissions & Ownership
chmod— Change file permissions. Example:chmod 755 file.txtchown— Change file owner. Example:chown user:group file.txt
4. Process Management
ps— Display a list of currently running processes.top— Interactive display of system processes.kill— Send a signal to terminate a process. Example:kill PIDbg/fg— Resume jobs in the background/foreground.
5. Networking
ping— Test network connectivity. Example:ping google.comcurl— Transfer data from or to a server. Example:curl http://example.comwget— Download files from the internet.ifconfig/ip— Display or configure network interfaces.
6. Compression & Archiving
tar— Archive multiple files into a tarball. Example:tar -cvf archive.tar filesgzipandgunzip— Compress/decompress files.zipandunzip— Archive/compress files with.zipformat.
7. Disk Usage
df— Display disk space usage. Example:df -hdu— Display directory or file space usage. Example:du -sh /path
8. System Information
uname— Display system information. Example:uname -auptime— Show how long the system has been running.free— Display memory usage.who— Show who is logged into the system.top— Display real-time system usage (CPU, memory, etc.)
9. Package Management (for Ubuntu/Debian)
apt-get update— Update package lists.apt-get install— Install new packages.apt-get remove— Remove packages.
10. Text Processing
grep— Search text using patterns. Example:grep "pattern" file.txtawk— Process and analyze text files.sed— Stream editor for filtering and transforming text.
11. Redirection & Piping
>— Redirect output to a file. Example:ls > file.txt>>— Append output to a file.|— Pipe output to another command. Example:ls | grep "txt"
12. Shell Scripting Essentials
echo— Print text to the screen. Useful in scripts.&&and||— Logical operators for chaining commands.for,while,if— Loop and condition structures for scripting.
13. Environment & Variables
export— Set environment variables. Example:export PATH=$PATH:/new/pathenv— Display environment variables.unset— Remove environment variables. Example:unset VARIABLE
14. System Cleanup
history— Display command history.clear— Clear the terminal screen.alias— Create shortcuts for commands. Example:alias ll='ls -la'
15. Powerful One-Liners
du -h --max-depth=1— Show sizes of directories and files in current directory.find . -type f -mtime -1— Find files modified in the last day.grep -r "text" /path— Recursively search for "text" in files under/path.
These commands cover a broad range of tasks, from navigating and managing files to process control and scripting. They’re essential for efficient workflow and automation in the Bash environment!