Basic concept for Linux beginner

Posted by Md. Mahidul Hasan on 6:25 AM with No comments
Basic concept for Linux beginner

Linux basics:
1.   Create a file
2.   Create a folder
3.   Copy a file
4.   Copy a folder with its subfolders and files
5.   Move a file
6.   Move a folder with its subfolders and files
7.   Copy a folder with its subfolders and files from one workstation to another workstation
8.    move a folder with its subfolders and files from one workstation to another workstation
9.    Rename a file or folder
10.  Delete/Remove a file
11.  Delete/Remove a folder with its subfolders and files
12.  Delete/Remove all files and folders
13.  Make a tarball (compress file) file
14.  Untar a tar file
15.  Install software from a tar file
16.  Change a file/folder permission
17.  Change a file/folder ownership
18.  Create a ping and traceroute report


File and folder concept:

Create a new file and folder:
1. We can create file two ways. One using “touch” command and second using your text editor like- vim, vi, nano etc. To create a new file named “info” follow this step-
~# touch info

2. If you use vim editor it will create and also open the info file.
~# vim info

If you want to write anything press “Insert” button and start typing. After that if you want to save the document press “Esc+wq!”.  If you don’t want to save it press “Esc+q!”

3. If you want to make a folder name folder1 then follow this-
~# mkdir folder1

 
Copy file and folder:

1. If you want to copy a file named test1 from (/home) to (/etc) follow this step-
~# cp /home/test1 /etc/test1

2. If you want to copy all files without folders from (/home) to (/etc) follow this step-
~# cp /home/* /etc

3. If you want to copy a folder named folder1 from (/home) to (/etc) follow this step-
~# cp -R /home/folder1 /etc/folder1

4. If you want to copy all files with folders from (/home) to (/etc) follow this step-
~# cp -R /home/* /etc


Move file and folder:
1. If you want to move a file named test1 from (/home) to (/etc) follow this step-
~# mv /home/test1 /etc/test1

2. If you want to move all files without folders from (/home) to (/etc) follow this step-
~# mv /home/* /etc

3. If you want to move a folder named folder1 from (/home) to (/etc) follow this step-
~# mv -R /home/folder1 /etc/folder1

4. If you want to move all files with folders from (/home) to (/etc) follow this step-
~# mv -R /home/* /etc

 
Tarball Concept: (question 13 & 14)

Available tarball format:
       1. tar (store file permissions)
       2. tgz (store file permissions)
       3. zip (does not store file permissions)

Create your tarball:
Usage / Syntax:  command [-options] /location/of/new/file.tar /files/to/archive

Options:
 -c = create
 -f = read to/from the named file (instead of the device /tape)
 -t = list contents of .tar file
 -r = append to a .tar file
 -v = verbose (tells you everything its doing)
 -x = extract contents of .tar file
 -z = compress files (not so useful for minc files)

Example 1:
~# tar -cvf /goto/myfile.tar /goto/mydir/results/stat/*

Example 2: make the software folder to software.tar
~# tar -czvf software.tar software

Example 3: If you want to make the software folder as a tarball and save it to the other location (/home/mahidul) with a new file name. and included with the content of (/root)
~# tar -czvf /home/mahidul/test.tar /root/software

Example 4: To create a tar archive of an entire directory including all files and sub-directories:
~# tar -cvf mytarfile.tar mydir/

Example 5: For a more universally compatible file try (The problem with the zip format is that it does not store file permissions.)
~# zip -rv9 myzipfile.zip /mydir


Extract files from your tarball:
Example 1: first go to the location (/home/mahidul/) of your tar file. Then untar your (test.tar) file like this way-
~# tar -xzvf /home/mahidul/test.tar