Basic Shell Scripts that everyone should know

ยท

2 min read

CommandCommand Full nameExampleWork
lslistlslists all folder and file inside of a directory and prints them
cdchange directorycd userschanges directory into another directory.
mkdirmake directorymkdir newfoldercreates a new directory.
pwdpresent working directorypwdprints the current directory path.
touchtouchtouch newfilecreates a file.
vivisual editorvi newfilecreates a file and edit immediately.
nanonanonano filenameopens the file in an editor.
catcatcat filenameprints the contents of the file in the shell.
rmremoverm -r filenameRemoves a file or folder
free

free -g | free | free | prints how much memory is being used and available. | | nproc | number of processors | nproc | prints number of processing units available. | | df | disk usage in file system | df -h | prints how much disk space is being used in file system. | | top | top | top | prints a real-time view of the running processes and displays kernel managed tasks. | | man | manual | man ls | prints details of a command | | history | history | history | prints all the commands the user used |

Shebang

Shebang is the first line of a shell script which indicates which interpreter will be used to run the script.

Usually, it starts with #! and the line of code is something like this:

#!/bin/user/bash

chmod

chmod (Change mode bits) is a special command to change the mode of access of a directory or a file.

It has 3 parts in it which are defined by number.

  1. What is the permission for my user?

  2. What is the permission for my user group?

  3. What is the permission for the other users?

๐Ÿ‘‰๐Ÿผ 7 is the highest permission number for any access. Linux uses 4 for read, 2 for write and 1 for execute.

ย