Unix Commands Flashcards

1
Q

Clear

A

clear
-clears the current the screen and displays prompt at the top of the screen

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

pwd

A

pwd
-shows the absolute path (from the root) to the present working directory (i.e. the directory you are currently in)

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

LS

A

The output from ls contains many pieces of information.
Each line represents one directory or file. The first character of the line indicates
what it is.
If the first character is a “d”, the item is a directory.
If the first character is a dash “-“, then the item is simply a file.
The next set of characters indicate file permission bit

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

CD

A

to move between directories, we use the cd (change directory) command
If you’re moving to a directory in the current directory, you can use cd dirname, where “dirname” is the name of the directory (case sensitive)

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

mkdir

A

The mkdir command stands for \make directory”.
It is used to create a directory or folder.
Syntax: mkdir dirname
Here, “dirname” is the name of the new directory you want to create.
This will create a directory with the given name in the current directory.

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

rmdir

A

The rmdir command stands for \remove directory”.
It is used to delete the given (empty) directory.
Syntax: rmdir dirname
Here, \dirname” is the name of the new directory you want to delete.
This will delete a directory with the given name in the current directory, as
long as it is empty. It will fail if the directory contains other files or directories.
These files have to be deleted first, before deleting the directory.

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

cp

A

The cp command is used to copy files.
Syntax: cp sourcefile destinationfile

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

mv

A

The mv command is use to move a file.
Syntax: mv sourcefile destinationfile

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

rm

A

The rm command is used to remove (delete) a file.
Syntax: rm filename.
Here, “filename” is the name of the file you want to delete.
Once the file is deleted, it has been deleted forever, and cannot be
recovered.

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

using wild cards

A

In any unix commands that deal with paths and file names, you can use wild
cards.
The wild card characters are the question mark (?) and the asterisk (*).
The question mark ? can be substituted in a filename, and it will represent
any character in that position.
For example consider the command mv prog?.cpp ./temp
The ? in the above command says that the command applies to any filename
matching that pattern, in which the ? can represent any character (like a wild
card in a poker hand).

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

man

A

man refers to \manual”, and unix systems provide pages of the manual that
can be accessed from the command prompt.
You can get further information on any unix command or system call with the
command:
man <commandname></commandname>

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

file permissions - chmod

A

You have control over the permissions on your own directories and files.
You can limit permissions to just yourself, or you can allow other people to
access your les and run your programs.
You can do this on a file by file basis, if you like. To change your file
permissions, you use the chmod (change mode) command.
There are several ways to use the chmod command, but the easiest format
is:
chmod <permission> <file>
The permission list can be given with a numerical code. The basic format is
to use a 3 digit number (4 digits are possible, for more advanced options).</file></permission>

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

more/less

A

The “more” command in unix allows you to display a file one screenful at a
time.
After each screenful, you will see “-More-“ at the bottom.
You can advance the file one line at a time with the Return key, or you can
advance a page at a time with the Spacebar.
“less” is a command that is similar to “more” and is available in some unix
systems.
It allows the viewing of a file, like “more”, but it also allows backward
movement through the file while viewing, as well as forward movement.

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

diff

A

diff compares two text files ( can also be used on directories) and prints the lines for which the files differ. The
format is as follows:
diff [options] <original> <newfile>
Some options
* [-b] Treats groups of spaces as one
* [-i] Ignores case
* [-r] Includes directories in comparison
* [-w] Ignores all spaces and tabs</newfile></original>

<original> - Specifies one file to compare
<newfile> - Specifies other file to compare
Example:
diff -w testprog1.c testprog2.c
</newfile></original>

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

grep

A

grep is a very useful utility that searches files for a particular pattern.
The pattern can be a word, a string enclosed in single quotes, or a regular expression.
usage
●grep int .c (find all occurences of the pattern ‘int’ in all files with a .c extenstion)
●grep ‘main()’ testprog1.c (enclosing the pattern in quotes is useful when using special characters)
●grep ‘m.
n’ myfile (the . matches a single character, the .* matches any number of characters; this
finds anything starting with an m and ending with an n)
The way that regular expressions can be described is somewhat complex in grep: see the following
tutorial for more help:
grep has many options; a few are noted below
-i ignore case -n display the line numbers
-l display only names of files and not actual lines

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

tar

A

Tar is a utility for creating and extracting archives. It is very useful for archiving files on disk, sending a set of files
over the network, and for compactly making backups
●General form: tar options filenames
●Commonly used Options
-c insert files into a tar file
-f use the name of the tar file that is specified
-v output the name of each file as it is inserted into or
extracted from a tar file
-x extract the files from a tar file
-t list contents of an archive
-z will gzip / gunzip if necessary