Let's Talk About BASH
BASH stands for Bourne Again Shell. It was released in 1989 as a reincarnation of the Bourne Shell, the then default shell on Unix systems. It was programmed by Stephen Bourne and came as a replacement for Thompson Shell, the first ever shell software for UNIX. The old Bourne Shell is still present in some Unix systems. You can usually find it as
/bin/sh. However, even that has been replaced by BASH on most modern distributions; both /bin/sh and /bin/bash are executables for BASH.Working with Directories and Files
The things everyone must do in a command line environment is navigate the file system, create, delete, copy and move file system objects, and execute commands. This may be common knowledge to some of you, but let’s take a quick look:
A line-by-line explanation:
1. mkdir - Create a directory called Sample under /home/sjayapriya
2. cd - Change current directory to newly created directory
3. Create a directory called "AnotherDir" inside the current directory
4. touch - Create an empty file inside "AnotherDir" using the touch command.
5. Change current directory to AnotherDir using cd command
6. pushd- Use pushd to change directory to ~/Sample in order to put our current directory on a stack
7.ls - list all files in ~/Sample
8. popd - Return to our previous directory by issuing a popd command, which fetches (and removes) the top directory from stack.
9. List again the contents and see the file(myfile) we created above.
Input/Output
Every command must communicate with the command line environment. Commands need input and provide output. Standard Input refers to source from where a command can read information. This is the keyboard by default, and it’s frequently referred to as “stdin”. Standard Output refers to the place where a command’s output will be sent. By default, this is the current console, and its usually referred to as “stdout”.Standard Error refers to the place where a command outputs its errors. This is the current console by default, and many refer to it as “stderr”.
In Unix, everything is a file.Your keyboard is a file, your mouse is a file, your screen is a file,programs are in files,text is in files,etc.
A file descriptor is an integer that the operating system's kernel uses to reference open files. Every system has at least three file descriptors.
- Descriptor no.0 - standard input
- Descriptor no.1 - standard output
- Descriptor no.2 - standard error
How to search for files in the Console
You basically have two options when you need to search for files in the console. The first is the
locate command. It is usually, but not necessarily, installed on many modern Linux distributions. The updatedb command indexes your files and locate uses that database to find your files. It does not actually do a real-time search, it simply looks up indexes in a database. That’s why this application is usually scheduled for a daily updatedb.The second command is find. This command performs a real-time search.It is more accurate than locate, but is obviously much slower.Let's Talk About Permissions
Users and Groups
There can be several users on the same computer. In fact, several applications register their own special user and use it to run the program in a restricted environment. Each user can be identified by their name and/or their ID, also known as UID. You can find the list of the currently existing users in the file /etc/passwd.Groups are listed in the file
/etc/group. A group has a name and ID (known as GID), and a group is a container of zero or more users. Each user usually has at least one corresponding group, which has the same name as the user.
The Owner
Files have owners, and the user that creates a file is, by default, its owner. Directories are just special files, and they have the same owner and permission rules as ordinary files.
There are three types of file permissions.
There are three types of file permissions.
- r-read
- w-write
- x-execute
The three permission types are applied to three categories
- User- the rights for the owner user
- Group- the permissions for the owner group
- Others - the permissions for other users attempting to access our file or folder
The
chmod command sets global permissions on a file system object, and its syntax is: chmod +/-rights path. Using a + means you enable a right, and - means you remove a right. You can specify any combination of rights.
But at some point, everything in computing comes down to a binary string. The
chown command allows you to easily specify permissions using a decimal representation of the binary permissions.rwx: Each bit is set to 1: 111. Which in decimal is 7.rw-: Is represented as 110. Which in decimal is 6.r-x: Is represented as 101. Which in decimal is 5.r--: Is represented as 100. Which in decimal is 4.-wx: Is represented as 011. Which in decimal is 3.-w-: Is represented as 010. Which in decimal is 2.--x: Is represented as 001. Which in decimal is 1.---: Is represented as 000. Which in decimal is 0.
The
chown command can accept a string of three numbers between 0 and 7. Each digit represents the rights for a specific category in order: user, group, others.
A Little Networking
Ping
The
ping command is an easy way to check if a server is up and accessible.Its syntax is easy:
ping IP_address_or_name. If the server is accessible, you will see a list of reply lines with details. If it’s not, an error message states the problem.(8.8.8.8 is Google's DNS Server)Traceroute
The
traceroute command displays the route a packet takes from your computer to the destination device.Current Network Connections
Another useful command is
netstat. It can list all the network connections to the system, as well as the IPs, interfaces and ports the system listens on. Here is a part of netstat‘s output on my system. I shortened it to eliminate irrelevant informationFinally!
So there you have it: some of the most used CLI commands! Naturally, each of these commands are capable of much more than what I’ve covered here :). I hope I’ve shed a bit of light on some of these CLI mysteries. Thanks for reading!
No comments:
Post a Comment