Linux Commands Flashcards
$ exit
closes the terminal emulator window
$ date
displays the current time and date
$ cal
displays a calender of the current month
$ pwd
prints full path of current working directory
$ cd
changes directory (to root without giving pathname)
$ ls
lists directory content
$ cd /some/path/name
$ cd ~/some/path/name
changes directory by given absolut path, which starts with the root “/” or with ~ as representation of the root followed by some directories
.
..
one dot represents the current working directory
two dots represent the parent directory of the current working directory
- absolute pathname
2. realtive pathname
- an absolute pathname starts from the root directory /
- a relative pathname starts from the working directory . /
In almost all cases, we can omit the ./ part because it is implied because ./ means the working directory, but we start a relative part always from the working directory. Simply wrinting “ cd name_of_subdirectory” is enough.
How can you see hidden files?
Filenames that begin with a period character are hidden. This means that “ls” will not list them unless you enter “ls -a”.
How should filenames be written in Linux?
Filenames and commands in Linux are case sensitive. Most important, do not embed spaces in filenames. If you want to represent spaces between words in a filename, use underscore characters. File extensions are not necessary.
$ cd -
changes the working directory to the previous working directory
$ cd ~user_name
changes the working directory to the home directory of user_name
$ ls
lists content of working directory
$ ls /some/path/name
lists the content of the directory, specified by this pathname, without changing the current working directory
$ ls -l
lists the content in long detailed form of the working directory
- $ ls -lt
2. $ ls -lt –reverse
- lists the content in long detailed form “-l” and sorts the content by the modification time “-t” of the current working directory
- reverses the order of the sorted content
$ ls -a (–all)
lists all files, even those with names that begin with a period, which are normally not listed (that is, hidden)
$ ls -A (–almost-all)
lists like the -a option hidden files except it does not list .(current directory) and ..(parent directory)
$ ls -d (–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.
$ ls -F (–classify)
This option will append an indicator character to the end of each listed name. For example, it will append a forward slash (/) if the name is a directory.
$ ls -h (–human readable)
In long format listings (in combination with -l), displays file sizes in human-readable format rather than in bytes.
$ ls -r (–reverse)
Displays the content of the working directory in reverse order. Normally, ls displays its results in ascending alphabetical order.
$ ls -S
Sorts the content of the working directory by file size.
$ ls -t
Sorts the content of the working directory by modification time.
$ file name_of_file
The file command will print a brief description of the file’s (name_of_file) contents.
$ less name_of_file
The less command is a program to view text files, like configuration files, program-scripts, etc. If we accidently attempt to view a non-text file and it scrambles the terminal window, we can recover by entering the “reset” command.
$ less name_of _file
Name typical less commands, that can be used once the less programm starts and enables the view of the content of the file (name_of_file).
PAGE UP or b Scroll back one page
PAGE DOWN or space Scroll forward one page
Up arrow Scroll up one line
Down arrow Scroll down one line
G Move to the end of the text file
1G or g Move to the beginning of the text file
/characters Search forward to the next occurrence of characters
n Search for the next occurrence of the previous search
h Display help sreen
q Quit less
What is the copy-and -paste trick when using a mouse?
If you are using a mouse, you can double-click a filename to copy it and middle-click to paste it into commands.
What is the meaing of this wildcard: *
- Matches any characters
What is the meaning of this wildcard: ?
? Matches any single character
What is the meaning of this wildcard: [characters]
[characters] Matches any character that is a member of the set characters
What is the meaning of this wildcard: [!characters]
[!characters] Matches any charachter that is not a member of the set characters
What is the meaning of this wildcard: [[:class:]]
[[:class:]] Matches any character that is a member of the specified class
Name commonly used character classes
[:alnm:] Matches any alphanumerical character
[: alpa:] Matches any alphabetic character
[:digit:] Matches any numeral
[:lower:] Matches any lower case letter
[:upper:] Matches any uppercase letter
How can you select all files of a directory?
*
How can you select any file beginning with “ g “?
g*
How can you select any file beginning with “ b “ followed by any characters and ending with “ .text “ ?
b*.txt
How can you select any file beginning with either “ a “, or “ b “, or “ c “ ?
[abc]*
How can you select any file beginning with “ Data “ followed by exactly three characters?
Data???
How can you select any file beginning with “ BACKUP. “ followed by exactly three numerals?
BACKUP. [0-9][0-9][0-9]
How can you select any file beginning with an uppercase letter?
[[:upper:]]*
How can you select any file beginning with a numeral?
[![:digit:]]*
How can you select any file ending with a lowercase letter or the numerals 1, 2, or 3?
*[[:lower:]123]
How can you create a directory?
$ mkdir name_of _directory
How can you create three directories named dir1, dir2, dir3?
$ mkdir dir1 dir2 dir3
How can you copy the single file or directory “item1” to the file or directory “item2”?
$ cp item1 item2
How can you copy “item1”, “item2” and “item3” to the directory “dir1” ?
$ cp item1 item2 item 3 dir1