.bash_aliasesfile in your home directory.
catcommand (short for “concatenate”) lists the contents of files to the terminal window. This is faster than opening the file in an editor, and there’s no chance you can accidentally alter the file. To read the contents of your
.bash_log_outfile, type the following command while the home directory is your current working directory, as it is by default:
lessto make the process more manageable. With
lessyou can scroll forward and backward through the file using the Up and Down Arrow keys, the PgUp and PgDn keys, and the Home and End keys. Type
qto quit from less.
cdcommand changes your current directory. In other words, it moves you to a new place in the filesystem.
cdand the name of the other directory.
~(tilde) character as the directory name.
..to represent the parent of the current directory. You can type the following command to go up a directory:
..symbol to shorten what you have to type.
chmodcommand sets the file permissions flags on a file or folder. The flags define who can read, write to or execute the file. When you list files with the
-l(long format) option you’ll see a string of characters that look like
-the item is a file, if it is a
dthe item is a directory. The rest of the string is three sets of three characters. From the left, the first three represent the file permissions of the owner, the middle three represent the file permissions of the group and the rightmost three characters represent the permissions for others. In each set, an
rstands for read, a
wstands for write, and an
xstands for execute.
xcharacter is present that file permission is granted. If the letter is not present and a
-appears instead, that file permission is not granted.
chmodis to provide the permissions you wish to give to the owner, group, and others as a 3 digit number. The leftmost digit represents the owner. The middle digit represents the group. The rightmost digit represents the others. The digits you can use and what they represent are listed here:
rwx. That means everyone has read, write and execute rights with the file.
chowncommand allows you to change the owner and group owner of a file. Listing our example.txt file with
ls -lwe can see
kaipulla vvsin the file description. The first of these indicates the name of the file owner, which in this case is the user
kaipulla. The second entry shows that the name of the group owner is also
vvs. (short form of Varuathapadadha Vaalibar Sangam) Each user has a default group created when the user is created. That user is the only member of that group. This shows that the file is not shared with any other groups of users.
chownto change the owner or group, or both of a file. You must provide the name of the owner and the group, separated by a
:character. You will need to use
sudo. To retain kaipulla as the owner of the file but to set vvs as the group owner, use this command:
curlcommand is a tool to retrieve information and files from Uniform Resource Locators (URLs) or internet addresses.
curlcommand may not be provided as a standard part of your Linux distribution. Use
apt-getto install this package onto your system if you’re using Ubuntu or another Debian-based distribution. On other Linux distributions, use your Linux distribution’s package management tool instead.
curlhowever, we can retrieve the file we want on its own.
-o(output) option. If you do not do this, the contents of the file are scrolled rapidly in the terminal window but not saved to your computer.
dfcommand shows the size, used space, and available space on the mounted filesystems of your computer.
-h(human readable) and
-x(exclude) options. The human-readable option displays the sizes in Mb or Gb instead of in bytes. The exclude option allows you to tell
dfto discount filesystems you are not interested in. For example, the
squashfspseudo-filesystems that are created when you install an application with the
diffcommand compares two text files and shows the differences between them. There are many options to tailor the display to your requirements.
-y(side by side) option shows the line differences side by side. The
-w(width) option lets you specify the maximum line width to use to avoid wraparound lines. The two files are called alpha1.txt and alpha2.txt in this example. The
difffrom listing the matching lines, letting you focus on the lines which have differences.
echocommand prints (echoes) a string of text to the terminal window.
echocommand can show the value of environment variables, for example, the
$PATHenvironment variables. These hold the values of the name of the user, the user’s home directory, and the path searched for matching commands when the user types something on the command line.
findcommand to track down files that you know exist if you can’t remember where you put them. You must tell
findwhere to start searching from and what it is looking for. In this example, the
.matches the current folder and the
findto look for files with a name that matches the search pattern.
*represents any sequence of characters and
?represents any single character. We’re using
*ones*to match any file name containing the sequence “ones.” This would match words like bones, stones, and lonesome.
findhas returned a list of matches. One of them is a directory called Ramones. We can tell
findto restrict the search to files only. We do this using the
-typeoption with the
fparameter stands for files.
fingercommand gives you a short dump of information about a user, including the time of the user’s last login, the user’s home directory, and the user account’s full name.
freecommand gives you a summary of the memory usage with your computer. It does this for both the main Random Access Memory (RAM) and swap memory. The
-h(human) option is used to provide human-friendly numbers and units. Without this option, the figures are presented in bytes.
greputility searches for lines which contain a search pattern. When we looked at the alias command, we used
grepto search through the output of another program,
grepcommand can also search the contents of files. Here we’re searching for the word “train” in all text files in the current directory.
groupscommand tells you which groups a user is a member of.
gzipcommand compresses files. By default, it removes the original file and leaves you with the compressed version. To retain both the original and the compressed version, use the
headcommand gives you a listing of the first 10 lines of a file. If you want to see fewer or more lines, use the
-n(number) option. In this example, we use
headwith its default of 10 lines. We then repeat the command asking for only five lines.
!and the number of the command from the history list.
killcommand allows you to terminate a process from the command line. You do this by providing the process ID (PID) of the process to
kill. Don’t kill processes willy-nilly. You need to have a good reason to do so. In this example, we’ll pretend the
shutterprogram has locked up.
shutterwe’ll use our
greptrick from the section about the
aliascommand, above. We can search for the
shutterprocess and obtain its PID as follows:
lesscommand allows you to view files without opening an editor. It’s faster to use, and there’s no chance of you inadvertently modifying the file. With
lessyou can scroll forward and backward through the file using the Up and Down Arrow keys, the PgUp and PgDn keys and the Home and End keys. Press the Q key to
less. To see the output from
lsfor a listing of your entire hard drive, use the following command:
/to search forward in the file and use
?to search backward.
lslooks in the current directory. There are a great many options you can use with
ls, and we strongly advise reviewing its the man page. Some common examples are presented here.
-a(all files) option:
less. The man pages are the user manual for that command. Because
lessto display the man pages, you can use the search capabilities of
chown, use the following command:
qto quit the man page or press
mkdircommand allows you to create new directories in the filesystem. You must provide the name of the new directory to
mkdir. If the new directory is not going to be within the current directory, you must provide the path to the new directory.
-p(parents) option to have
mkdircreate all of the required parent directories too.
mkdircreate all the specified directories at once:
mvcommand allows you to move files and directories from directory to directory. It also allows you to rename files.
mvwhere the file is and where you want it to be moved to. In this example, we’re moving a file called
kaipulla.pdffrom the “~/Document/Vadivelu” directory and placing it in the current directory, represented by the single
passwdcommand lets you change the password for a user. Just type
passwdto change your own password.
sudo. You will be asked to enter the new password twice.
pingcommand lets you verify that you have network connectivity with another network device. It is commonly used to help troubleshoot networking issues. To use
ping, provide the IP address or machine name of the other device.
pingcommand will run until you stop it with Ctrl+C.
pingto run for a specific number of ping attempts, use the
pscommand lists running processes. Using
pswithout any options causes it to list the processes running in the current shell.
-u(user) option. This is likely to be a long list, so for convenience pipe it through
-e(every process) option:
pwdcommand prints the working directory (the current directory) from the root / directory.
shutdownwith no parameters will shut down your computer in one minute.
shutdowncommand know when you want it to shut down, you provide it with a time. This can be a set number of minutes from now, such as
+90or a precise time, like
23:00. Any text message you provide is broadcast to logged in users.
wcommand to list the current users on “howtogeek” system. She is listed as being connected from pts/1, which is a pseudo-terminal slave. That is, it is not a terminal directly connected to the computer.
exitand is returned to the shell on the “Nostromo” computer.
sudocommand is required when performing actions that require root or superuser permissions, such as changing the password for another user.
tailcommand gives you a listing of the last 10 lines of a file. If you want to see fewer or more lines, use the
-n(number) option. In this example, we use
tailwith its default of 10 lines. We then repeat the command asking for only five lines.
tarcommand, you can create an archive file (also called a tarball) that can contain many other files. This makes it much more convenient to distribute a collection of files. You can also use
tarto extract the files from an archive file. It is common to ask
tarto compress the archive. If you do not ask for compression, the archive file is created uncompressed.
tarwhich files to include in the archive file, and the name you wish the archive file to have.
-c(create) option and the
-v(verbose) option. The verbose option gives some visual feedback by listing the files to the terminal window as they are added to the archive. The
-f(filename) option is followed by the desired name of the archive. In this case, it is
tarthat you want the archive file to be compressed. The first is with the
-z(gzip) option. This tells tar to use the
gziputility to compress the archive once it has been created.
tarto correctly retrieve the files.
-joption is noticeably slower than the
-zoption for decent compression and reasonable speed, or the
-joption for better compression and slower speed.
-x(extract) option. The
-f(filename) options behave as they do when creating archives. Use
lsto confirm which type of archive you are going to extract the files from, then issue the following command.
-joption instead of the
topcommand shows you a real-time display of the data relating to your Linux machine. The top of the screen is a status summary.
-a(all) option to see everything.
-s(kernel name) option to see the type of kernel.
-r(kernel release) option to see the kernel release.
-v(kernel version) option to see the kernel version.
wcommand lists the currently logged in users.
whoamito find out who you are logged in as or who is logged into an unmanned Linux terminal.