0% found this document useful (0 votes)
18 views9 pages

I Basic Linux

Uploaded by

Anthony Gozo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
18 views9 pages

I Basic Linux

Uploaded by

Anthony Gozo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

A.

LINUX FILESYSTEM HIERARCHY

Learning to work with Command Line Interface (CLI) is a skill needed in order to
proficiently administer Linux Systems, all of the configurations will be done using CLI. Thus,
succeeding lectures will be more focused on basic Linux commands used in CLI environment. The
initial step in order to learn Linux administration is to be familiarized to different directories.

Procedures:
1. Open CentOS in Oracle VirtualBox
2. Go command line interface by right clicking on desktop, in options provided choose Open in
terminal.
3. In command line, type in cd / (change directory to root) and ls (list).

Take note:
All of the hardisk present in Linux system (C: D: etc.) are collated under the root directory (/).

You have to understand what are the significant of such directories (folder) in Linux System.

Linux machine was built for multi-user environment. (Server).

2 major types of user

1. Regular user – created accounts to used Linux machine


2. Superuser/ Root user (Admin account)

Linux came from Unix, also the MS-DOS.

Exe (Copy.exe, format.exe) in Linux, it is equivalent to binaries.

The reason why it is being categorized into two user, regular and superuser is to give the regular
user a certain binaries to be executed. There are commands that cannot be used by the user, so it should
be then categorized.

Linux directories under root

1. bin – binaries for regular users (It can also be executed by admin)
2. sbin - binaries for the superuser/ root user
3. home – home directory of regular users
Take note that Linux is intended by multi-user environment, just like window:
In windows,
C:\user\karlo\
C:\user\minlee\
In Linux,
Same thing goes with Linux:
karlo/home/karlo
minlee/home/minlee

4. root (slash root) – home directory of root user.


5. var – variable files ( FTP files, email, web etc. )
▪ You have to allocate space, which depends upon its specific use.
6. etc – system configs
▪ We are going to configure servers.
7. boot- kernel , bootloaders
▪ The operating system of linux is called kernel
8. dev – in Llnux, everything is a file, including hardisk and other device file.
9. proc – system processes

All of the content of the directories are tend to be non-distractive, it means that once you have
restarted your Linux PC, its content will not be deleted except for /proc. The said directory contains
temporary files for the purpose of viewing the system processes (same as task manager in windows
operating system)

Cloning image in Virtual Box


1. Clone image based on existing image
▪ Make sure that the existing image is turned off.
▪ Machine → Clone → rename (Basic Linux) → Clone type→ Full Clone → Snapshots →
Current machine state. Tick check box → Reinitialize mac → click Clone.
2. Start the Basic Linux image.

Absolute and Relative Path

Absolute Path - File location with respect to the root directory (/)
Example in windows:
C:\users\john\my documents\my pictures \ bora 2017 \ myprofilepic.jpeg
/home/john/my documents/my pictures/bora/myprofilepic.jpeg

Relative Path – file location relative to your present directory.


Change directory → home, change directory → until myprofilepic.jpeg
B. BASIC LINUX COMMANDS

What to Learn?

• New Folder
• Copy Paste File
• Copy Paste Folder
• Cut and Paste File
• Cut and Paste Folder
• Rename File
• Rename Folder
• Delete File
• Delete Folder
• Present Working Directory
• Change Directory
• Up one directory
• Listing Files

New Folder mkdir <directory name>


New File touch <filename>
Copy Paste File cp <source> <destination>
Copy Paste Folder cp -r <source> <destination>
Cut and Paste File mv <source> <destination>
Cut and Paste Folder mv <source> <destination>
Rename File mv <orig filename> <new filename>
Rename Folder mv <orig filename> <new filename>
Delete File rm <filename>
Delete Folder rm -r <dirname>
Present Working Directory pwd
Change Directory cd <directory name>
Up one Directory cd ..
Listing Files ls; ls <directory name>

COPY AND PASTING

#pwd Take note: Commands in Linux are


Go to / (root directory) case sensitive, it should be lowercase
#cd /
Verify: #pwd

✓ CREATE NEW DIRECTORY → /sample dir

#mkdir /sampledir
VERIFY: #ls ls – list all contents of the current
#clear - > to clear terminal directory
Go to /sampledir • Linux has autocomplete feature
#cd /sampledir
VERIFY: # pwd you can also do ls in
remote directory
✓ CREATE THESE DIRECTORIES ls <directory name>
• Dir1
• Dir2 Linux has history function, use up arrow
• Dir3 to go to the previous command. You
• Dir4 can also do ls in remote directory
• Dir5 ls <directory name>

#mkdir <dir name>

✓ CREATE THESE FILES INSIDE /sampledir

• File1
• File2 2 ways to verify:
#ls – you have to be inside the
• File3
/sampledir (Relative Path)
• File4
• File5 #ls /sampledir (Absolute Path)
#touch <filename>
#touch file1
#verify
#ls

✓ COPY AND PASTE FILE


▪ Copy – paste are executed in cp
cp <source> <destination> command

2 ways to copy and paste file


SCENARIO: Copy file1 PASTE TO dir1 ▪ Copy and paste file, retail
filename
ABSOLUTE PATH: ▪ Copy and paste file, new
filename
# cp <source> <destination>
#cp /sampledir/file1 /sampledir/dir1
VERIFY: #ls /sampledir/dir1

RELATIVE PATH:

*Before using relative path, you have to make sure that you are inside their parent directory

#pwd
#cp file1 dir1
# VERIFY: ls dir1

Copy and paste file, new filename

SCENARIO: COPY file2, Paste to /dir3, new filename file2copy

ABSOLUTE PATHS:

SYNTAX: # cp <source> <destination>


cp /sampledir/file2 /sampledir/dir3/file2copy

RELATIVE PATH:
#cp file2 dir3/file2copy
#VERIFY
#ls dir3
#ls /sampledir/dir3

✓ COPYING AND PASTING FOLDERS

SCENARIO: Copy dir1, paste to dir2 , retain filename


SYNTAX:#cp <source> <destination> MANUAL OR INFO COMMAND
#man cp
ABSOLUTE PATH: #info cp
#cp /sampledir/dir1 /sampledir/dir2
#cp: omitting directory

SCENARIO: copy DIR2, paste to dir5, new FILENAME dir2copy

ABSOLUTE PATH:
#cp –r /sampledir/dir2 /sampledir/dir5/dir2copy

RELATIVE PATH:
#cp –r dir2 dir5/dir2copy

VERIFY:
#ls /sampledir/dir5
#ls dir5

✓ CUT AND PASTE FILES

SYNTAX:
#mv <source> <destination>

SCENARIO: Cut file1 PASTE TO dir2, RETAIN FILENAME

ABSOLUTE PATHS

SYNTAX: #mv <source> <destination>


#mv /sampledir/file1 /sampledir/dir2

RELATIVE PATH
#pwd
#mv file1 dir2

Once you click tab2x, it will list the file.

#VERIFY #ls /sampledir/dir2


#ls dir2

SCENARIO: CUT file2, PASTE INTO dir5, FILENAME filecut

ABSOLUTE PATH:
#mv /sampledir/file2 /sampledir/dir5/file2cut

RELATIVE PATH:
#pwd
#mv file2 dir5/file2cut

VERIFY:
#ls /sampledir/dir5
#ls dir5

✓ CUT AND PASTE FOLDER/DIRECTORIES

SYNTAX:
#mv <source> <destination>
*no need to type in –r
SCENARIO:CUT dir1 PASTE INTO dir4, retain file name

ABSOLUTE PATHS:
#mv /sampledir/dir1 /sampledir/dir4

RELATIVE PATHS:
#pwd
#mv dir1 dir5

VERIFY: #ls /sampledir/dir4


#ls dir4

SCENARIO: CUT dir2, PASTE INTO dir3, FILENAME dir2cut

ABSOLUTE PATH:
#mv /sampledir/dir2 /sampledir/dir3/dir2cut

RELATIVE PATH:
#pwd
#mv dir2 dir3/dir2cut

✓ RENAMING FILES AND DIRECTORIES

#mv <original filename> <new filename> =cut and paste with a new filename

SCENARIO: RENAME file3 into file3new


ABSOLUTE PATH:
#mv /sampledir/file3 /sampledir/file3new

RELATIVE PATH:
#mv file3 file3new
#VERIFY
#ls sampledir

✓ RENAMING FOLDER IS THE SAME AS RENAMING FILE:

SCENARIO: RENAME dir3, into dir3new

ABSOLUTE PATHS:
#mv /sampledir/dir3 /sampledir/dir3new
VERIFY: # ls sampledir

✓ DELETING FILES AND DIRECTORIES

#rm <filename>

SCENARIO: delete file4


SYNTAX: #rm <filename>

ABSOLUTE PATH:
#rm /sampledir/file4

RELATIVE PATH:
#rm file4

✓ DELETING DIRECTORIES

SYNTAX: rm –r <directory name>


SCENARIO: DELETE dir4 Note: You can alter command so as to
SYNTAX: #RM –R <dirname> immediately delete the directories w/o
typing in ‘y’).
ABSOLUTE PATH:
#rm –r /sampledir/dir4 We will use another option
-r → recursive
RELATIVE PATH: -f → force
#rm –r dir4
Note: be careful with this command,
*type in ‘y’ since Linux is not just like windows that
VERIFY: has recycle bin.
#ls

SCENARIO: FORCE DELETE dir5

#rm –rf dir5


#rm –rf /sample/dir5
#rm –rf /  scenario
VERIFY:
#ls

ANOTHER WAY TO REMOVE DIRECTORY:

SYNTAX:
#rmdir dir3new

CREATE A NEW DIRECTORY, blankdir


#mkdir blankdir

REMOVE blankdir USING rmdir COMMAND


#rmdir blankdir

CHAPTER EXERCISE:
1. GO TO /
2. CREATE A NEW DIRECTORY /practicedir
3. GO INTO /practicedir
4. CREATE THESE DIRECTORIES
a. dir1
b. dir2
c. dir3
d. dir4
e. dir5
5. CREATE THESE FILES
a. file1
b. file2
c. file3
d. file4
e. file5
6. COPY file1 TO dir1, RETAIN FILENAME
7. COPY file2 TO dir2, GIVE A NEW FILENAME copiedfile2
8. COPY dir1 TO dir5, RETAIN FILENAME
9. COPY dir2 TO dir4, GIVE A NEW FILENAME dir2copy
10. CUT file2 PASTE TO dir1, RETAIN FILENAME
11. CUT file3 PASTE TO dir4, GIVE A NEW FILENAME file3cut
12. CUT dir3 PASTE TO dir4, RETAIN FILENAME
13. CUT dir1 PASTE TO dir2, GIVE A NEW FILENAME dir1cut
14. RENAME file4 TO file4new
15. RENAME dir4 TO dir4new
16. DELETE file5
17. DELETE dir3

You might also like