Linux shell is a program that allows text-based interaction between the user and the computer
Types of shell in Linux
Linux Commands
Linux command consists of program name followed by the option and arguments.
For ex.
cat-n myfile
# program name: cat# option: -n# argument: myfile
Home directory
The home directory is a directory that stores user-specific data.
this data can be of any type
for ex. If there is a user named john, then john's data like images, documents, downloads, etc. data will reside in /home/john/ location
How to know the Home directory
echo$HOME# This command will read from the environment variable $HOMEecho ~
# This command will expand the tilde symbol to the given user's home directory path
Directory Management
How to know your current path
To know the current path, we use the command pwd, which stands for Present working directory
pwd
How to create & remove directories
mkdir is a command that is used to create a directory
rmdir is a command that is used to delete an empty directory
example
# to create a directorymkdir test_directory
# to create multiple directoriesmkdir test1 test2 test3
# to delete a directoryrmdir test_directory
# to remove multiple directoriesrmdir test1 test2 test3
How to list the content of a folder
to list the content of a directory we use the ls command
# to list the content of a directoryls
How to create a chain of directories
in order to perform this we use the "-p" parameter with mkdir command
Example
# We want to create 4 directories each inside of it's parent directorymkdir-p a/b/c/d
How to navigate through directories
To switch directories we use cd command
# Changing to the parent directorycd ../
# Changing to the home directorycd /home/user1
How to navigate folder directory in Linux
there are two types of path notation in Linux
1. Relative Path
2. Absolute Path
Relative path
relative path is defined with respect to the current directory
"." represents the current working folder
".." represents the parent directory
For example
# to change to the parent directory for the current directorycd ../
# to run a file/script present in the current directory
bash ./example.sh
Absolute path
absolute paths are defined with respect to the root "/" location
for example
# navigating to the user1 document foldercd /home/user1/documents
PUSHD & POPD
pushd and popd commands are used to manage the directory stack.
Example
# we created 3 directoriesmkdir-p a/b/c
# now we navigate to c directory using pushd command, by pushing it's path to directory stackpushd a/b/c
# this command will take us to the given c directory and we can create a file hereecho"hello world"> test_file.txt
# to navigate to the previous path we can use popd command# this will bring us to the parent directorypopd
Would love to see something about pushd and popd in addition to cd. They can be very handy tools when you changing directories a lot and need to make a quick escape to where you've previously been! :)
I think an important concept is also where a user's shell is defined.
A user's shell is typically setup when the user is added to the system. Often /bin/bash is set as a default, but macOS now sets /bin/zsh as the default shell for users.
A user could find their default shell by viewing the /etc/passwd file. For example,
In the above example root's default shell is set to the Bash shell. While the games user actually has been set to a nologin shell, preventing anyone from logging into the user. This has certain uses for non-interactive user sessions. We have other shell options that we can use as well. There are lots of varieties and it depends on your OS, or what the administrator has set at account creation.
There are different commands to modify a user's shell. But one way you can do this is with the usermod command:
usermod -s /bin/bash USER
If you want to find a list of available shells on your system, try this command: cat /etc/shells
There's no such thing as a Linux shell. There are only various shells, e.g., bash, tcsh, zsh, etc. You can use exactly the same shells on FreeBSD, macOS, and others as you can on Linux.
I have been a software professional since I was in high school in 1998. I'm enthusiastic about open source, and I really enjoy working in unusual software systems or within strange constraints.
I’m glad to see folks still talking about the terminal. That said, none of this is bash-specific. These will all work in a variety of shells, and I hope folks find whatever shell they prefer and have a great time in the shell.
You mention commands, but never once mention the PATH environment variable or explain that commands like mkdir "live" in certain directories and the way commands work is that the shell searches PATH for a matching command.
Top comments (13)
Would love to see something about pushd and popd in addition to cd. They can be very handy tools when you changing directories a lot and need to make a quick escape to where you've previously been! :)
Can't wait to see more!
Thanks for your response, i'll keep updating this page.
I think an important concept is also where a user's shell is defined.
A user's shell is typically setup when the user is added to the system. Often /bin/bash is set as a default, but macOS now sets /bin/zsh as the default shell for users.
A user could find their default shell by viewing the
/etc/passwd
file. For example,In the above example root's default shell is set to the Bash shell. While the games user actually has been set to a nologin shell, preventing anyone from logging into the user. This has certain uses for non-interactive user sessions. We have other shell options that we can use as well. There are lots of varieties and it depends on your OS, or what the administrator has set at account creation.
There are different commands to modify a user's shell. But one way you can do this is with the usermod command:
usermod -s /bin/bash USER
If you want to find a list of available shells on your system, try this command:
cat /etc/shells
There's no such thing as a Linux shell. There are only various shells, e.g., bash, tcsh, zsh, etc. You can use exactly the same shells on FreeBSD, macOS, and others as you can on Linux.
@pauljlucas Yeah, you are correct mate, thanks for the help, i've updated the title accordingly.
You might want to reconsider the banner image and
#linux
tag as well.You still mention "Linux shell....". You ought to replace that with "A shell...."
sure, i'm working on it
I’m glad to see folks still talking about the terminal. That said, none of this is bash-specific. These will all work in a variety of shells, and I hope folks find whatever shell they prefer and have a great time in the shell.
You mention commands, but never once mention the
PATH
environment variable or explain that commands likemkdir
"live" in certain directories and the way commands work is that the shell searchesPATH
for a matching command.In my opinion "how bash works" is also an important topic for a beginners, Don't you think so?
Beginners with no experience with bash, see the black screen and don't know what to write on it.
From my Teaching experience, they are more interested in, How to use it.
not "How it works".
I hope you understood my point, sir.
Thanks for your Feedback though
Some comments may only be visible to logged-in visitors. Sign in to view all comments.