Basic Linux Commands with Examples

Evren Yortuçboylu
Student Id: 110020110
Lecturer: Erke Arýbaþ
CRN: 30068
Homework 4


Question 1. ls
List contents of directories. If no names are given, list the files in the current directory. With one or more names, list files contained in a directory name or that match a file name. Names can include filename metacharacters. The options let you display a variety of information in different formats.

As shown in example, using ls command without parameters, lists all files and folders in current directory.
[yortucboy1@hyperion yortucboy1]$ ls
aData1.exe   bData2                   mbox
asp          bData3                   @@ mp3
bData1       C++                      public_html
bData11      evren.txt                Samples
bData1.exe   gitar                    Thumbs.db
Question 2. mkdir
Create one or more directories. You must have write permission in the parent directory in order to create a directory.
Creation of a folder named “deneme_klasoru”, shown in example.
[yortucboy1@hyperion yortucboy1]$ mkdir deneme_klasoru
Question 3. cp
Copy file1 to file2, or copy one or more files to the same names under directory. If the destination is an existing file, the file is overwritten; if the destination is an existing directory, the file is copied into the directory (the directory is not overwritten).
[yortucboy1@hyperion yortucboy1]$ cp bData1.exe bData_copy.exe
Question 4. mv
Move command, does the same as cp command except moves the file instead of copying it. It is also used to rename files/directories.
Rename the file bData.exe as newfile.doc: 
[yortucboy1@hyperion yortucboy1]$ mv bData.exe newfile.exe 

Move the file evren.txt to the asp folder
[yortucboy1@hyperion yortucboy1]$ mv evren.txt  asp
Question 5. rm
Delete one or more files. To remove a file, you must have write permission in the directory that contains the file.
Example command removes file named evren.txt
[yortucboy1@hyperion yortucboy1]$ rm evren.txt
Question 6. find
A Command for finding particular groups of files and folders. The find command descends the directory tree beginning at each pathname and locates files that meet the specified conditions. The default pathname is the current directory. The most useful conditions include -name and –type.
Finds and lists all text files (using txt file extension) in the asp directory.
[yortucboy1@hyperion yortucboy1]$ find asp –name *.txt

Finds and lists all direcroties in belgeler folder, including subfolders.
[yortucboy1@hyperion yortucboy1]$ find  belgeler –type d
Question 7. chmod
Changes the permissions of each given file according to MODE.
Numeric mode:
From one to four octal digits
Any omitted digits are assumed to be leading zeros.

The first digit = selects attributes for the set user ID (4) and set group ID (2) and save text image (1)S
The second digit = permissions for the user who owns the file: read (4), write (2), and execute (1)
The third digit = permissions for other users in the file's group: read (4), write (2), and execute (1)
The fourth digit = permissions for other users NOT in the file's group: read (4), write (2), and execute (1)
The octal (0-7) value is calculated by adding up the values for each digit
User (rwx) = 4+2+1 = 7
Group(rx) = 4+1 = 5
World (rx) = 4+1 = 5
chmode mode = 0755
Example: Allow everyone to read, write, and execute the file evren.txt: 
[yortucboy1@hyperion yortucboy1]$ chmod 777 evren.txt
Question 8. tar
Copy files to or restore files from an archive medium.
General syntax of command is: 
tar [options] [tarfile] [other-files]

some of the most used options are;
-c  : create new archive
-x : extract other-files from an archive ((if other-files are not specified, extract all files).
-v : print filenames as they are added or  extracted 
-f : store files in or extract files from  archive file.

Example: Archive C++ folder in deneme.tar file.
[yortucboy1@hyperion yortucboy1]$ tar cvf deneme.tar C++ 
Question 9. cd
Changes the current working directory to a specific folder.
Change current directory to folder named VB.
[yortucboy1@hyperion yortucboy1]$ cd VB

Using two dots as parameter, moves up one folder.
[yortucboy1@hyperion VB]$ cd .. 
Question 10. cat
Reads (concatenate) one or more files and prints them on standard output. Read standard input if no files are specified or if - is specified as one of the files; input ends with EOF. Tthe > operator can be used to combine several files into a new file, or >> to append files to an existing file.
Example:
Displays evren.txt file
[yortucboy1@hyperion VB]$  cat evren.txt

Combines two filen (file1.txt and file2.txt) into one file (combination.txt)
[yortucboy1@hyperion VB]$  cat file1.txt file2.txt > combination.txt 

REFERENCES:
1.http://www.linuxdevcenter.com/linux/cmd/
2.http://ss64.com/bash
3.http://www.computerhope.com/unix.htm
4.manuals of linux bash shell.