avatarRavi M

Summarize

50 Essential Bash & Zsh Terminal Commands Every Developer Should Know

Command line proficiency is a crucial skill for developers and system administrators

Photo by Gabriel Heinzer on Unsplash

The command line is a powerful tool for developers to interact with their system, automate tasks, and boost productivity. Bash and Zsh are two of the most popular Unix shells that provide a wide range of built-in commands and scripting capabilities. In this article, we’ll explore 50 essential Bash and Zsh terminal commands that every developer should have in their toolbox.

Navigating the File System

1. pwd: Print the current working directory.

pwd

2. cd: Change the current directory.

cd /path/to/directory

3. ls: List files and directories.

ls -l

4. mkdir: Create a new directory.

mkdir new_directory

5. touch: Create a new file or update its timestamp.

touch file.txt

File Manipulation

6. cp: Copy files and directories.

cp file.txt backup/

7. mv: Move or rename files and directories.

mv old_name.txt new_name.txt

8. rm: Remove files and directories.

rm file.txt

9. cat: Concatenate and display file contents.

cat file.txt

10. head: Display the first few lines of a file.

head -n 10 file.txt

11. tail: Display the last few lines of a file.

tail -n 10 file.txt

Text Processing

12. grep: Search for patterns in files.

grep "pattern" file.txt

13. sed: Stream editor for filtering and transforming text.

sed 's/old/new/g' file.txt

14. awk: Text processing tool for advanced filtering and manipulation.

awk '{print $1}' file.txt

15. sort: Sort lines of text files.

sort file.txt

16. uniq: Remove duplicate lines from a sorted file.

uniq file.txt

Process Management

17. ps: Display information about running processes.

ps aux

18. top: Monitor system processes and resource usage.

top

19. kill: Terminate a process by its process ID.

kill 1234

20. bg: Send a process to the background.

command &

21. fg: Bring a background process to the foreground.

fg %1

Network Commands

22. ping: Test network connectivity to a host.

ping example.com

23. curl: Transfer data from or to a server using various protocols.

curl https://example.com

24. wget: Download files from the web.

wget https://example.com/file.zip

25. ssh: Securely connect to a remote server.

ssh user@example.com

26. scp: Securely copy files between hosts.

scp file.txt user@example.com:/path/

Compression and Archives

27. tar: Create or extract tar archives.

tar -cvf archive.tar files/

28. gzip: Compress or decompress files using gzip compression.

gzip file.txt

29. unzip: Extract compressed files from a ZIP archive.

unzip archive.zip

30. zip: Create a ZIP archive from files or directories.

zip -r archive.zip files/

System Information

31. uname: Display system information.

uname -a

32. df: Report disk space usage

df -h

33. du: Estimate file and directory space usage

du -sh directory/

34. free: Display the amount of free and used memory

free -h

35. uptime: Show how long the system has been running.

uptime

File Permissions

36. chmod: Change file permissions

chmod 755 file.sh

37. chown: Change file ownership

chown user:group file.txt

38. chgrp: Change the group ownership of files.

chgrp group file.txt

39. umask: Set the default file permissions.

umask 022

Environment Variables

40. env: Display environment variables

env

41. export: Set an environment variable

export VAR=value

42. unset: Remove an environment variable

unset VAR

43. source: Execute commands from a file in the current shell

source script.sh

Aliases and Functions

44. alias: Create an alias for a command.

alias ll='ls -l'

45. unalias: Remove an alias.

unalias ll

46. function: Define a shell function.

function greet() {
    echo "Hello, $1!"
}

Zsh-Specific Commands

47. take: Create a directory and change into it.

take project

48. zle: Zsh line editor for command line editing

zle -N my-widget

49. zmodload: Load Zsh modules.

zmodload zsh/datetime

50. zstyle: Configure Zsh styles and behaviors

zstyle ':completion:*' menu select

Conclusion:

Mastering the command line with Bash and zsh is an essential skill for developers and system administrators. By leveraging the power of shell scripting, environment customization, and best practices, you can significantly enhance your productivity and streamline your workflow.

Stackademic 🎓

Thank you for reading until the end. Before you go:

Command Line
Bash
Bash Script
Linux
Programming
Recommended from ReadMedium