Linux Commands Flashcards

0
Q

cal

A

Shows system calendar

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

date

A

Shows date

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

df

A

To see the current amount of free space on your disk drives

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

free

A

to display the amount of free memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

exit

A

to end a terminal session

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Ctrl- Alt-F1 through Ctrl-Alt-F6

A

To access virtual terminals or virtual consoles

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Alt and F1-F6

A

To switch from one virtual console to another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Alt-F7

A

To return to the graphical desk- top

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

pwd

A

Print name of current working directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

cd (argument)

A

Change directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

ls

A

List current working directory contents

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

.

A

The “.” symbol refers to the working directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

..

A

the “..” symbol refers to the working directory’s parent directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

cd

A

Changes the working directory to your home directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

cd -

A

Changes the working directory to the previous working directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

cd ~user_name

A

Changes the working directory to the home directory of user_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

ls -a

A

Shows hidden files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

ls (arg) (arg) …

A

To list the contents of one or more directories

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

ls -l

A

By adding “-l” to the command, we changed the output to the long format

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

command -options arguments

A

Overall style of a command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

ls -lt

A

many commands allow multiple short options to be strung together. In this example, the ls command is given two options, the “l” option to produce long format output, and the “t” option to sort the result by the file’s modification time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

ls -lt –reverse

A

Long options are preceded with two dashes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

ls -a

ls –all

A

List all files, even those with names that begin with a period, which are normally not listed (i.e., hidden)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

ls -A

ls –almost-all

A

Like the -a option above except it does not list . (current directory) and .. (parent directory)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
ls -d | ls --directory
Ordinarily, if a directory is specified, ls will list the contents of the directory, not the directory itself. Use this option in conjunction with the -l option to see details about the directory rather than its contents
25
ls -F | ls --classify
This option will append an indicator character to the end of each listed name. For example, a “/” if the name is a directory
26
ls -h | ls --human-readable
In long format listings, display file sizes in human readable format rather than in bytes
27
ls -l
Display results in long format
28
ls -r | ls --reverse
Display the results in reverse order. Normally, ls displays its results in ascending alphabetical order
29
ls -S
Sort results by file size
30
ls -t
Sort by modification time
31
ls Long Listing Fields: | -rw-r--r--
Access rights to the file. The first character indicates the type of file. Among the different types, a leading dash means a regular file, while a “d” indicates a directory. The next three characters are the access rights for the file's owner, the next three are for members of the file's group, and the final three are for everyone else. The full meaning of this is discussed in Chapter 9 – Permissions
32
ls Long Listing Fields: | 1
File's number of hard links. See the discussion of links later in this chapter
33
ls Long Listing Fields: | root
The username of the file's owner
34
ls Long Listing Fields: | root
The name of the group which owns the file
35
ls Long Listing Fields: | 32059
Size of the file in bytes
36
ls Long Listing Fields: | 2007-04-03 11:05
Date and time of the file's last modification
37
ls Long Listing Fields: | oo-cd-cover.odf
Name of the file
38
file (filename)
the file command will print a brief description of the file's contents
39
less (filename)
the less program allows you to scroll forward and backward through a text file. Once the less program starts, we can view the contents of the file. If the file is longer than one page, we can scroll up and down. To exit less, press the “q” key.
40
less Commands: | Page Up or b
Scroll back one page
41
less Commands: | Page Down or space
Scroll forward one page
42
less Commands: | Up Arrow
Scroll up one line
43
less Commands: | Down Arrow
Scroll down one line
44
less Commands: | G
Move to the end of the text file
45
less Commands: | 1G or g
Move to the beginning of the text file
46
less Commands: | /characters
Search forward to the next occurrence of characters
47
less Commands: | n
Search for the next occurrence of the previous search
48
less Commands: | h
Display help screen
49
less Commands: | q
Quit less
50
Directories Found On Linux Systems: | /
The root directory. Where everything begins.
51
Directories Found On Linux Systems: | /bin
Contains binaries (programs) that must be present for the system to boot and run.
52
Directories Found On Linux Systems: | /boot
Contains the Linux kernel, initial RAM disk image (for drivers needed at boot time), and the boot loader. Interesting files: ● /boot/grub/grub.conf or menu.lst, which are used to configure the boot loader. ● /boot/vmlinuz, the Linux kernel
53
Directories Found On Linux Systems: | /dev
This is a special directory which contains device nodes. “Everything is a file” also applies to devices. Here is where the kernel maintains a list of all the devices it understands.
54
Directories Found On Linux Systems: | /etc
The /etc directory contains all of the system-wide configuration files. It also contains a collection of shell scripts which start each of the system services at boot time. Everything in this directory should be readable text. Interesting files: While everything in /etc is interesting, here are some of my all-time favorites: ● /etc/crontab, a file that defines when automated jobs will run. ● /etc/fstab, a table of storage devices and their associated mount points. ● /etc/passwd, a list of the user accounts.
55
Directories Found On Linux Systems: | /home
In normal configurations, each user is given a directory in /home. Ordinary users can only write files in their home directories. This limitation protects the system from errant user activity.
56
Directories Found On Linux Systems: | /lib
Contains shared library files used by the core system programs. These are similar to DLLs in Windows.
57
Directories Found On Linux Systems: | /lost+found
Each formatted partition or device using a Linux file system, such as ext3, will have this directory. It is used in the case of a partial recovery from a file system corruption event. Unless something really bad has happened to your system, this directory will remain empty.
58
Directories Found On Linux Systems: | /media
On modern Linux systems the /media directory will contain the mount points for removable media such as USB drives, CD-ROMs, etc. that are mounted automatically at insertion.
59
Directories Found On Linux Systems: | /mnt
On older Linux systems, the /mnt directory contains mount points for removable devices that have been mounted manually.
60
Directories Found On Linux Systems: | /opt
The /opt directory is used to install “optional” software. This is mainly used to hold commercial software products that may be installed on your system.
61
Directories Found On Linux Systems: | /proc
The /proc directory is special. It's not a real file system in the sense of files stored on your hard drive. Rather, it is a virtual file system maintained by the Linux kernel. The “files” it contains are peepholes into the kernel itself. The files are readable and will give you a picture of how the kernel sees your computer.
62
Directories Found On Linux Systems: | /root
This is the home directory for the root account.
63
Directories Found On Linux Systems: | /sbin
This directory contains “system” binaries. These are programs that perform vital system tasks that are generally reserved for the superuser.
64
Directories Found On Linux Systems: | /tmp
The /tmp directory is intended for storage of temporary, transient files created by various programs. Some configurations cause this directory to be emptied each time the system is rebooted.
65
Directories Found On Linux Systems: | /usr
The /usr directory tree is likely the largest one on a Linux system. It contains all the programs and support files used by regular users.
66
Directories Found On Linux Systems: | /usr/bin
/usr/bin contains the executable programs installed by your Linux distribution. It is not uncommon for this directory to hold thousands of programs.
67
Directories Found On Linux Systems: | /usr/lib
The shared libraries for the programs in /usr/bin.
68
Directories Found On Linux Systems: | /usr/local
The /usr/local tree is where programs that are not included with your distribution but are intended for system- wide use are installed. Programs compiled from source code are normally installed in /usr/local/bin. On a newly installed Linux system, this tree exists, but it will be empty until the system administrator puts something in it.
69
Directories Found On Linux Systems: | /usr/sbin
Contains more system administration programs.
70
Directories Found On Linux Systems: | /usr/share
/usr/share contains all the shared data used by programs in /usr/bin. This includes things like default configuration files, icons, screen backgrounds, sound files, etc.
71
Directories Found On Linux Systems: | /usr/share/doc
Most packages installed on the system will include some kind of documentation. In /usr/share/doc, we will find documentation files organized by package.
72
Directories Found On Linux Systems: | /var
With the exception of /tmp and /home, the directories we have looked at so far remain relatively static, that is, their contents don't change. The /var directory tree is where data that is likely to change is stored. Various databases, spool files, user mail, etc. are located here.
73
Directories Found On Linux Systems: | /var/log
/var/log contains log files, records of various system activity. These are very important and should be monitored from time to time. The most useful one is /var/log/messages. Note that for security reasons on some systems, you must be the superuser to view log files .
74
Wildcards: | *
Matches any characters
75
Wildcards: | ?
Matches any single character
76
Wildcards: | [characters]
Matches any character that is a member of the set characters (just one character)
77
Wildcards: | [!characters]
Matches any character that is not a member of the set characters
78
Wildcards: | [[:class:]]
Matches any character that is a member of the specified class
79
Commonly Used Character Classes: | [:alnum:]
Matches any alphanumeric character
80
Commonly Used Character Classes: | [:alpha:]
Matches any alphabetic character
81
Commonly Used Character Classes: | [:digit:]
Matches any numeral
82
Commonly Used Character Classes: | [:lower:]
Matches any lowercase letter
83
Commonly Used Character Classes: | [:upper:]
Matches any uppercase letter
84
mkdir (arg)...
The mkdir command is used to create directories
85
cp item1 item2
to copy the single file or directory “item1” to file or directory “item2”. (If file2 exists, it is overwritten with the contents of file1)
86
cp item... directory
to copy multiple items (either files or directories) into a directory. (Directory must already exist)
87
cp -a | cp --archive
Copy the files and directories and all of their attributes, including ownerships and permissions. Normally, copies take on the default attributes of the user performing the copy.
88
cp -i | cp --interactive
Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, cp will silently overwrite files.
89
cp -r | cp --recursive
Recursively copy directories and their contents. This option (or the -a option) is required when copying directories.
90
cp -u | cp --update
When copying files from one directory to another, only copy files that either don't exist, or are newer than the existing corresponding files, in the destination directory.
91
cp -v | cp --verbose
Display informative messages as the copy is performed.
92
mv item1 item2
to move or rename file or directory “item1” to “item2”
93
mv item... directory
to move one or more items from one directory to another.
94
mv -i | mv --interactive
Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, mv will silently overwrite files.
95
mv -u | mv --update
When moving files from one directory to another, only move files that either don't exist, or are newer than the existing corresponding files in the destination directory.
96
mv -v | mv --verbose
Display informative messages as the move is performed.
97
cp -r dir1 dir2
Copy the contents of directory dir1 to directory dir2. If directory dir2 does not exist, it is created and, after the copy, will contain the same contents as directory dir1. If directory dir2 does exist, then directory dir1 (and its contents) will be copied into dir2.
98
mv dir1 dir2
If directory dir2 does not exist, create directory dir2 and move the contents of directory dir1 into dir2 and delete directory dir1. If directory dir2 does exist, move directory dir1 (and its contents) into directory dir2.
99
rm (arg)...
The rm command is used to remove (delete) files and directories
100
rm -i | rm --interactive
Before deleting an existing file, prompt the user for confirmation. If this option is not specified, rm will silently delete files.
101
rm -r | rm --recursive
Recursively delete directories. This means that if a directory being deleted has subdirectories, delete them too. To delete a directory, this option must be specified.
102
rm -f | rm --force
Ignore nonexistent files and do not prompt. This overrides the --interactive option.
103
rm -v | rm --verbose
Display informative messages as the deletion is performed.
104
ln file link
To create a hard link
105
ln -s item link
to create a symbolic link where “item” is either a file or a directory.
106
ls -i
Show the inode(the block chain of memory where the contents part of the file and not the name part or hard link lives) number.
107
type command
The type command is a shell builtin that displays the kind of command the shell will execute, given a particular command name. ( shell built in, executable program, shell function, alias)
108
which command
Display An Executable's Location ( works only on executable commands not other forms)
109
help command
bash has a built-in help facility available for each of the shell builtins. To use it, type “help” followed by the name of the shell builtin.
110
command --help
Many executable programs support a “--help” option that displays a description of the command's supported syntax and options.
111
man program
Most executable programs intended for command line use provide a formal piece of doc- umentation called a manual or man page. A special paging program called man is used to view them.
112
apropos term | man -k term
It is also possible to search the list of man pages for possible matches based on a search term.
113
whatis command
The whatis program displays the name and a one line description of a man page match- ing a specified keyword
114
info program
The GNU Project provides an alternative to man pages for their programs, called “info.” Info pages are displayed with a reader program named, appropriately enough, info. Info pages are hyperlinked much like web pages.
115
info Commands: | ?
Display command help
116
info Commands: | PgUp or Backspace
Display previous page
117
info Commands: | Enter
Follow the hyperlink at the cursor location
118
info Commands: | PgDn or Space
Display next page
119
info Commands: | n
Next - Display the next node
120
info Commands: | p
Previous - Display the previous node
121
info Commands: | u
Up - Display the parent node of the currently displayed node, usually a menu.
122
info Commands: | q
Quit
123
info coreutils
will display a menu page with hyperlinks to each program contained in the coreutils package.
124
/usr/share/doc gzip zless
Many software packages installed on your system have documentation files residing in the /usr/share/doc directory. Most of these are stored in plain text format and can be viewed with less. Some of the files are in HTML format and can be viewed with a web browser. We may encounter some files ending with a “.gz” extension. This indicates that they have been compressed with the gzip compression program. The gzip package includes a special version of less called zless that will display the contents of gzip- compressed text files.
125
alias name='string'
After the command “alias” we give alias a name followed immediately (no whitespace al- lowed) by an equals sign, followed immediately by a quoted string containing the mean- ing to be assigned to the name. After we define our alias, it can be used anywhere the shell would expect a command.
126
unalias (arg)
To remove an alias, the unalias command is used
127
alias
To see all the aliases defined in the environment, use the alias command without arguments.
128
>
To redirect standard output to another file instead of the screen, we use the “>” redirection operator followed by the name of the file.
129
> file-name
to actually truncate a file (or create a new, empty file)
130
>>
Using the “>>” operator will result in the output being appended to the file. If the file does not already exist, it is created just as though the “>” operator had been used.
131
(file descriptor)
A program can produce output on any of several numbered file streams. While we have referred to the first three of these file streams as standard input, output and error, the shell references them internally as file de- scriptors 0, 1 and 2, respectively. The shell provides a notation for redirecting files using the file descriptor number.
132
2>
Since standard error is the same as file descriptor number 2, we can redirect standard error with this notation.
133
example: ls -l /bin/usr > ls-output.txt 2>&1
Using this method, we perform two redirections. First we redirect standard output to the file ls-output.txt and then we redirect file descriptor 2 (standard error) to file de- scriptor one (standard output) using the notation 2>&1. (Order is significant)
134
example: ls -l /bin/usr &> ls-output.txt
In this example, we use the single notation &> to redirect both standard output and stan- dard error to the file ls-output.txt. You may also append the standard output and standard error streams to a single file like so: ls -l /bin/usr &>> ls-output.txt
135
example: ls -l /bin/usr 2> /dev/null
Sometimes “silence is golden,” and we don't want output from a command, we just want to throw it away. This applies particularly to error and status messages. The system pro- vides a way to do this by redirecting output to a special file called “/dev/null”. This file is a system device called a bit bucket which accepts input and does nothing with it. To sup- press error messages from a command, we do this.
136
/dev/null
This file is a system device called a bit bucket which accepts input and does nothing with it.
137
cat [file...]
The cat command reads one or more files and copies them to standard output.
138
example: cat movie.mpeg.0* > movie.mpeg
Since cat can accept more than one file as an argument, it can also be used to join files together. Say we have downloaded a large file that has been split into multiple parts (multimedia files are often split this way on Usenet), and we want to join them back together. If the files were named: movie.mpeg.001 movie.mpeg.002 ... movie.mpeg.099 we could join them back together with this command. Since wildcards always expand in sorted order, the arguments will be arranged in the cor- rect order.
139
cat
Enter a text by keyboard and hit Cntl-d to denote the end of the text. If not redirected anywhere cat will send the output to screen, if redirected to a file, you have made a text file.
140
cat > file
Cat reads its input not from keyboard but from a file.
141
command1 | command2
Using the pipe operator “|” (vertical bar), the standard output of one command can be piped into the standard input of another.
142
sort (input...)
Sort lines of text. | Sophisticated example: ls /bin /usr/bin | sort | less
143
uniq (input)
The uniq command is often used in conjunction with sort. uniq accepts a sorted list of data from either standard input or a single filename argument (see the uniq man page for details) and, by default, removes any duplicates from the list.
144
uniq -d
If we want to see the list of duplicates instead, we add the “-d” option to uniq.
145
wc | wc -l
``` The wc (word count) command is used to display the number of lines, words, and bytes contained in files. if executed without command line arguments, wc accepts standard input. The “-l” option limits its output to only report lines. Adding it to a pipeline is a handy way to count things. ```
146
grep pattern [file...]
When grep encounters a “pattern” in the file, it prints out the lines containing it.
147
grep -i | grep -v
“-i” which causes grep to ignore case when performing the search (normally searches are case sensitive) and “-v” which tells grep to only print lines that do not match the pattern.
148
example: head -n 5 ls-output.txt example: tail -n 5 ls-output.txt example: ls /usr/bin | tail -n 5
The head command prints the first ten lines of a file and the tail command prints the last ten lines. By default, both commands print ten lines of text, but this can be adjusted with the “-n” option.
149
tail -f
tail has an option which allows you to view files in real-time. This is useful for watch- ing the progress of log files as they are being written. Using the “-f” option, tail continues to monitor the file and when new lines are ap- pended, they immediately appear on the display. This continues until you type Ctrl-c.
150
tee
The tee program reads standard input and copies it to both standard output (allowing the data to continue down the pipeline) and to one or more files. This is useful for capturing a pipeline's contents at an intermediate stage of processing. example: ls /usr/bin | tee ls.txt | grep zip
151
Tilde Expansion:
echo ~ /home/me echo ~foo /home/foo
152
Arithmetic Expansion:
$((expression)) example: echo $(((5**2) * 3)) Operators: +, -, *, /, %, ** Operates on integers only.
153
echo (arg)
echo is a shell builtin that performs a very simple task. It prints out its text arguments on standard out- put.
154
Brace Expansion:
Patterns to be brace expanded may contain a leading portion called a preamble and a trailing portion called a postscript. The brace expression itself may contain either a comma-separated list of strings, or a range of integers or single characters. The pattern may not contain embedded whitespace. Examples: [me@linuxbox ~]$ echo Front-{A,B,C}-Back Front-A-Back Front-B-Back Front-C-Back [me@linuxbox ~]$ echo Number_{1..5} Number_1 Number_2 Number_3 Number_4 Number_5 [me@linuxbox ~]$ echo {01..15} 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 [me@linuxbox ~]$ echo {001..15} 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 [me@linuxbox ~]$ echo {Z..A} Z Y X W VU T S R Q P O N M L K J I H G F E D C B A [me@linuxbox ~]$ echo a{A{1,2},B{3,4}}b aA1b aA2b aB3b aB4b mkdir {2007..2009}-{01..12} ls 2007-01 2007-07 2008-01 2008-07 2009-01 2009-07 2007-02 2007-08 2008-02 2008-08 2009-02 2009-08 2007-03 2007-09 2008-03 2008-09 2009-03 2009-09 2007-04 2007-10 2008-04 2008-10 2009-04 2009-10 2007-05 2007-11 2008-05 2008-11 2009-05 2009-11 2007-06 2007-12 2008-06 2008-12 2009-06 2009-12
155
Parameter Expansion:
Many of its capabilities have to do with the system's ability to store small chunks of data and to give each chunk a name. Many such chunks, more properly called variables, are available for your examination. example: echo $USER To see a list of available variables, try this: printenv | less
156
Command Substitution:
Command substitution allows us to use the output of a command as an expansion. Examples: [me@linuxbox ~]$ echo $(ls) Desktop Documents ls-output.txt Music Pictures Public Templates Videos [me@linuxbox ~]$ ls -l $(which cp) -rwxr-xr-x 1 root root 71516 2007-12-05 08:58 /bin/cp [me@linuxbox ~]$ file $(ls -d /usr/bin/* | grep zip)
157
example: | [me@linuxbox ~]$ ls -l `which cp` -rwxr-xr-x 1 root root 71516 2007-12-05 08:58 /bin/cp
There is an alternate syntax for command substitution in older shell programs which is also supported in bash. It uses back-quotes instead of the dollar sign and parentheses.