The shell Flashcards
What is Bash?
“Bourne Again Shell”
other common shells include sh, csh, tcsh, will also be referenced in this tutorial, and they sometime differ from bash
How can shell scripting be accomplished?
by directly executing shell commands at the shell prompt or by storing them in the order of execution, in a text file, called a shell script, and then executing the shell script. To execute, simply write the shell script file name, once the file has execute permission (chmod +x filename)
What is “the shell”?
Simply put, the shell is a program that takes commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix-like system such as Linux. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell.
What is a “terminal”?
It’s a program called a terminal emulator. This is a program that opens a window and lets you interact with the shell. There are a bunch of different terminal emulators you can use. Most Linux distributions supply several, such as: gnome-terminal, konsole, xterm, rxvt, kvt, nxterm, and eterm.
separate commands in one line
;
Command history
Up/down arrows
If you’re not logged in as root, what are you?
If the last character of your shell prompt is # rather than $, you are operating as the superuser. This means that you have administrative privileges. This can be potentially dangerous, since you are able to delete or overwrite any file on the system. Unless you absolutely need administrative privileges, do not operate as the superuser.
Why do you need to learn the command line anyway?
Graphical user interfaces (GUIs) are helpful for many tasks, but they are not good for all tasks. I have long felt that most computers today are not powered by electricity. They instead seem to be powered by the “pumping” motion of the mouse! Computers were supposed to free us from manual labor, but how many times have you performed some task you felt sure the computer should be able to do but you ended up doing the work yourself by tediously working the mouse? Pointing and clicking, pointing and clicking.
pwd
The directory you are standing in is called the working directory. To find the name of the working directory, use the pwd command.
Stands for “print working directory”
ls
list the files in the working directory
Stands for “list”
cd
Change the working directory (cd followed by the pathname)
Absolute vs. relative path names
Where an absolute pathname starts from the root directory and leads to its destination, a relative pathname starts from the working directory. To do this, it uses a couple of special notations to represent relative positions in the file system tree. These special notations are “.” (dot) and “..” (dot dot).
The “.” notation refers to the working directory itself and the “..” notation refers to the working directory’s parent directory
Root directory
/
User directory (or home directory/where you start out normally)
~
cd followed by nothing
Shortcut to change working directory to your home directory
cd ~user_name
Change to home directory of specified user
Hidden files
File names that begin with a period character are hidden. This only means that ls will not list them unless you say ls -a. When your account was created, several hidden files were placed in your home directory to configure things for your account. Later on we will take a closer look at some of these files to see how you can customize your environment. In addition, some applications will place their configuration and settings files in your home directory as hidden files.
File names in Linux, like Unix, are…
case sensitive. The file names “File1” and “file1” refer to different files.
Linux has no concept of…
a “file extension” like legacy operating systems. You may name files any way you like. However, while Linux itself does not care about file extensions, many application programs do.
Punctuation in file names
Though Linux supports long file names which may contain embedded spaces and punctuation characters, limit the punctuation characters to period, dash, and underscore. Most importantly, do not embed spaces in file names. If you want to represent spaces between words in a file name, use underscore characters. You will thank yourself later.
Most commonly used command
probably ls
List files in a directory
ls /bin (/bin is just a directory for this example)
List the files in the working directory in long format
ls -l
long-form shows a lot more info, like:
File Name
-The name of the file or directory.
Modification Time
-The last time the file was modified. If the last modification occurred more than six months in the past, the date and year are displayed. Otherwise, the time of day is shown.
Size
-The size of the file in bytes.
Group
-The name of the group that has file permissions in addition to the file’s owner.
Owner
-The name of the user who owns the file.
File Permissions
-A representation of the file’s access permissions. The first character is the type of file. A “-“ indicates a regular (ordinary) file. A “d” indicates a directory. The second set of three characters represent the read, write, and execution rights of the file’s owner. The next three represent the rights of the file’s group, and the final three represent the rights granted to everybody else. I’ll discuss this in more detail in a later lesson.
List files in long format in multiple directories
ls -l dir_1 dir_2