Top 10 Bash commands every new Bash developer should know
-
echo - Used to display lines of text or variables. Frequently used for debugging scripts or showing instructions.
echo "Usage: $0 <filename> <username> <hostname> <destination_directory>"
-
exit - Exits the current shell with a return code, useful for signaling success or failure of the script to the calling process.
exit 1
-
if - Used for conditional branching in scripts, which lets you execute commands only if certain conditions are met.
if [ ! -r $filename ]; then echo "Filename '$filename' does not exist" exit 1 fi
-
[ ] - Test expression to evaluate conditions within if statements. It checks file attributes, string values, and performs arithmetic comparisons.
[ $# -lt 4 ]
-
sftp - Secure File Transfer Protocol, a command used to securely transfer files over a network.
sftp -q -b - $port_string $username@$hostname
-
cd - Changes the directory inside a script or a command line; it’s fundamental for navigation within the filesystem.
cd $destination_directory
-
put - A command used within sftp sessions to upload files from local to remote systems.
put $filename
-
bye - Exits an sftp session. It’s important to close sessions properly to free up resources.
bye
-
-P (capital P in sftp) - Specifies the port number for connections, allowing the script to connect using non-default SSH ports.
-P $port
-
-q (in sftp) - Stands for ‘quiet’; suppresses most of the command messages and progress meters, making output cleaner especially in automated scripts.
sftp -q
These commands form the backbone of many scripting tasks in Bash and are critical for tasks such as automation, maintenance, and system administration.
Labels: Top 10 Bash commands
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home