Javascript required
Skip to content Skip to sidebar Skip to footer

What to Enter at the Command Promt to Start New Borune Again Shell

Cover image for An Overview of Bash(Bourne Again Shell) Command Line

DSC CIET profile image Neeraj Gupta

An Overview of Bash(Bourne Once more Shell) Command Line

Allow's Discuss

In Today'south life knowing how to communicate with your computers is important. In, Before days, when in that location was no Graphical Interface(GUI), people used to interact with computers through commands or we can say they used to give certain predefined commands to perform sure tasks.Merely, in today's earth everything has shifted to graphic based interfaces.Today's generation has just forgotten how powerful is command line and how much deep admission it gives you over your machine.

Annotation : If you directly start messing with control line without it's bones knowledge you may end up messing up with some files which are not meant to exist although command line do give alerts or ask for permissions but yous know we don't take that much patience and nosotros simply ignore that.

How to open control line(For Linux and MacOS)

For Linux Users

You can use Ctrl + Alt + T to directly open concluding/Command Line.

It, will wait something like this depending on your Linux Distribution(In Screenshot Ubuntu(Linux distribution) is used).

Notation : In taskbar pane you volition see an icon something like the one shown in the following image.

For MacOS Users

  1. Printing Control + Spacebar, It volition open your Spotlight.
  2. Search for Last and Press Enter/Return.
  3. It volition open a terminal window like the one shown in following image.

The app in Dock volition look something like the 1 shown below.

So, now we are washed with setting upward part and now nosotros volition move on to learning the commands

Jumping off to commands in BASH

1. ls - List Directory

ls is ane of the most used commands in fustigate command line.It helps u.s. to list files of directory which we want to show.

  1. Syntax : ls [option(southward)] [directory/directories(seperated by space)]
  2. Command Options :
    • -a : all. Lists all the files in the directory, including the hidden files (.filename).
    • -l : long. Lists details well-nigh contents, including permissions (modes), owner, group, size, creation engagement.

2. echo : Prints text to command line

repeat is used to output text to screen and is typically used to print variables condition or trounce status to screen or a computer file.

  • Syntax : echo[options(s)] [string(s)]
  • Command Options :
    • -northward : Used to suppress trailing newline.
    • -eastward : Used to enable estimation of backslash-escaped character like '\n'.

3. mkdir : Create a new directory

mkdir is important ane if you are wondering how the people in old fourth dimension used to create directories without Graphical User Interface(GUI). So, here is the command used to create new directories.

  • Syntax : mkdir [selection(southward)] [directory_name]
  • Command Options:
    • -p : This option is used to create all directories at once including parent and child directories. Ex : li -p a/b/c volition create folder named a at present directory and b inside it and c inside b.
    • -m : Used to create directory forth with which we tin can specify modes we want to requite to that directory. Ex : mkdir -yard a=rwx new means that create a folder named new at present directory and give it read, write and execute permissions.

4. impact : Creates a file

Upto now we accept seen some interacting commands and now here is another i to create a file of any type. Permit'south say you want to create a text file with proper noun "myFile". Then, you will write impact myFile.txt in control line. Also, it can be used in cases where nosotros want to overwrite data or modify timestamp of a file.

  • Syntax : touch on [option(s)] [filename(s)]
  • Control Options :
    • -a : Change the admission fourth dimension but. Ex : touch -a newFile.txt. This will modify the concluding access time of that file to current time.
    • -m : Change the modification time only. Ex : impact -thousand newFile.txt. This volition update the creation time of the file that means it will change the time the file was created to the current one.
    • -c : If the file do not exist, do not create it. Ex : touch -c textFile.txt. This says that if the file named textFile.txt is present then overwrite it otherwise do non create a new one.
    • -r : Utilize the modification and access times only. Ex : touch -r myFile.txt newFile.txt. This says alter the timestamp of newFile.txt with that of myFile.txt.
    • -t : Creates the file using a specified time. Ex : touch -t YYMMDDHHMM.SS newFile.txt.

five. pwd : Impress working directory

Here comes the another important command in bash that you will frequently use while working with directories that is pwd command. As, the proper name suggests it prints the current directory you are in.

  • Syntax : pwd
  • Command Options : Control options aren't used with pwd.

six. cd : Alter Directory

Another important command while y'all are working between directories. If, you lot wonder how former generation managed to move between directories of their computers without GUI. Hither'due south the solution cd. As the proper name suggests information technology is used to move between directories

  • Syntax : cd [directory_name(tin can include subclasses seperated by '/')]
  • Command Options : cd typically exercise not utilize options.

7. mv : Move or rename Directory

mv command is another life saver while working with directories. Sometimes we want to rename a file then mv can be used. This command really servers two purposes that is moving and renaming that purely depends on syntax you are using. If y'all are using syntax for renaming information technology will rename file else move it.

  • Syntax for renaming : affect [old_name] [new_name]. Here old name means the proper name before renaming and new_name ways the name you want your file/directory to change to.
  • Syntax for moving : touch [directory_you_want_to_move] [destination_directory].
  • Command Options :
    • -i(Interactive) : It enquire the user for confirmation before moving a file that would overwrite an existing file, you lot have to press y for confirm moving, any other key leaves the file as information technology is. This option doesn't work if the file doesn't exist, it but rename it or motion it to new location.
    • -b(backup): With this pick it is easier to accept a backup of an existing file that will exist overwritten as a result of the mv command. This will create a backup file with the tilde character(~) appended to it.

8. cp : Copy Files and Directory

cp command is another life saver while working with directories. Sometimes we desire to make a copy of file/directory and then cp can exist used. This command makes a copy of file(southward)/directory(s)

  • Syntax : cp Source_file Destination_file/directory
  • In case Destination file/directory is not present information technology will create a new one else information technology volition overwrite it.

  • Command Options :
    • -i(interactive): i stands for Interactive copying. With this option arrangement showtime warns the user before overwriting the destination file. cp prompts for a response, if y'all press y then it overwrites the file and with any other choice go out information technology uncopied.
    • -b(backup): With this option cp control creates the fill-in of the destination file in the same folder with the dissimilar proper noun and in unlike format.

9. rmdir : Remove Directory

Like mkdir is used to create directory(southward),rmdir is used to remove directory(southward).

Note : rmdir is used to only delete empty diretory(s). But, don't worry we accept an alternate to remove non-empty directory(s).

  • Syntax : rmdir [directory_name(s)]
  • Command Options : -p - remove the kid directory if empty otherwise gives error and and so besides deletes the parent directory.
  • Ex : rmdir -p a/b

    It will remove b if it is empty and then removes a.

x. rm : Remove Here

Here is the control which i was talking about earlier(rmdir). rm control is used to remove references to files, symbolic links and others. It is generally not used with directories, but in case of non-empty directories we use this command.

  • Syntax : rm [choice(south)] [file_name]
  • Command Options :
    • -i (Interactive Deletion) : Like in case of cp and mv, when we apply this option it asks for confirmation before removing each file. Press y for yeah and northward for no.
    • -f (Force Deletion) : If our files are write protected and so nosotros use -f option to bypass security check and forcefully delete the file.
    • -r (Recursive Deletion) : This option iterates/moves through all the files and delete each file(s) and sub-directory(s) recursively of the parent directory. At each stage it deletes everything it finds. Normally, rm wouldn't delete the directories only when used with this selection, information technology volition delete. And then, here is the answer to previous question that is How to delete not-empty directory .

11. cat : Read a file, create a file, and concatenate files

cat command is used to display, combine copies and create new file(s).

  • Syntax : cat [choice(s)] [file_name]
  • Command Options :
    • -northward : This options display the line number along with the contents of file.
    • Ex : touch -n new.txt. Here new.txt contains

    My name is Neeraj My hobbies include listening to music I love coding            

    And so, this command touch -north new.txt will show the output every bit

    1 My proper noun is Neeraj two My hobbies include listening to music 3 I dear coding            

    Now endeavour running this without pick -due north and you volition come across that information technology will now testify content merely and not the line number.

12. exit : Exit out a directory

exit command will stop the shell and end all the running tasks and if you lot are in remote SSH trounce, it volition log you out.

  • Syntax : get out
  • Command Options : n/a

xiii. clear : Clears the terminal window

articulate command will clear your previous used commands and other stuff from concluding window and will give you fresh terminal screen. Although previous used commands will remain in your history and y'all can admission them by click up pointer button.

  • Syntax : clear
  • Command Options : northward/a

14. history : List your about contempo commands

history command is used to display all the previous commands used in concluding

  • Syntax : history [pick]
  • Control Options :
    • -d : This option can be used if you want to clear a particular control from history
    • Syntax : history -d event_number. Consequence number tin exist plant using history command.

    • -c : This command option tin exist used to clear all history.
    • Syntax : history -c

/section>

xv. chmod : Sets the file permissions flag on a file or folder

There are situations that you'll come across where you or a colleague will try to upload a file or modify a document and yous receive an error because you lot don't have admission. The quick fix for this is to use chmod. Permissions tin be set with either alphanumeric characters (u, g, o) and can be assigned their access with west, r, x. Conversely, y'all can besides use octal numbers (0-7) to modify the permissions. For instance, chmod 777 my_file will give admission to anybody. In previous command kickoff seven is for owner of file, 2d vii is for groups, and third is for all others.

  • Syntax : chmod 777 new.txt
  • Command Options : -v (verbose) : Shows changed objects. In above control if you add -five choice and so information technology will output new.txt and will give access to everyone.

That's it for this web log.Cheers for reading this web log. If you found this blog useful so share it others, maybe it help them too. Run across yous all in side by side one.

finneyserthe.blogspot.com

Source: https://dev.to/dsc_ciet/an-overview-of-bash-bourne-again-shell-command-line-3d0l