0% found this document useful (0 votes)
64 views

Laborator Linux

This document provides an overview of the Linux file system structure and basic Linux commands. It describes the main directories in the Linux file system such as /bin, /boot, /dev, /etc, /home, and others. It also covers basic commands for navigation, such as ls, pwd, and paths. Further, it lists common file manipulation commands and tools for editing, compression, and text manipulation. The document serves as notes for Lab #1 on the Linux file system and basic commands.

Uploaded by

Popa Alex
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Laborator Linux

This document provides an overview of the Linux file system structure and basic Linux commands. It describes the main directories in the Linux file system such as /bin, /boot, /dev, /etc, /home, and others. It also covers basic commands for navigation, such as ls, pwd, and paths. Further, it lists common file manipulation commands and tools for editing, compression, and text manipulation. The document serves as notes for Lab #1 on the Linux file system and basic commands.

Uploaded by

Popa Alex
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Contents

Linux File System Structure................................................................................................................................................. 2


General overview ............................................................................................................................................................. 2
Level 1 directories ............................................................................................................................................................ 3
Linux Command line............................................................................................................................................................ 4
Navigation ............................................................................................................................................................................ 5
Basic commands................................................................................................................................................................... 6
Files and folders ................................................................................................................................................................... 7
Manual pages ....................................................................................................................................................................... 7
File editors............................................................................................................................................................................ 7
Text manipulation ................................................................................................................................................................ 7
Compression and archiving tools ......................................................................................................................................... 7
Appendix .............................................................................................................................................................................. 7
Links and notes .................................................................................................................................................................... 8

Lab #1 – Linux filesystem structure, basic commands, getting help in the text environment.
Extra tools(tar, zip, unzip), editors(nano, vim, mcedit), text manipulation(grep, awk, sed, cut)
Page 1 of 8
Linux File System Structure
General overview

Lab #1 – Linux filesystem structure, basic commands, getting help in the text environment.
Extra tools(tar, zip, unzip), editors(nano, vim, mcedit), text manipulation(grep, awk, sed, cut)
Page 2 of 8
Level 1 directories

Directory Content
/bin Common programs, shared by the system, the system administrator and the users.
The startup files and the kernel, vmlinuz. In some recent distributions also grub data.
/boot Grub is the GRand Unified Boot loader and is an attempt to get rid of the many
different boot-loaders we know today.
Contains references to all the CPU peripheral hardware, which are represented as files
/dev
with special properties.
Most important system configuration files are in /etc, this directory contains data
/etc
similar to those in the Control Panel in Windows
/home Home directories of the common users.
/initrd (on some distributions) Information for booting. Do not remove!
Library files, includes files for all kinds of programs needed by the system and the
/lib
users.
Every partition has a lost+found in its upper directory. Files that were saved during
/lost+found
failures are here.
/misc For miscellaneous purposes.
/mnt Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.
/net Standard mount point for entire remote file systems
/opt Typically contains extra and third party software.
A virtual file system containing information about system resources. More information
/proc about the meaning of the files in proc is obtained by entering the command man proc
in a terminal window. The file proc.txt discusses the virtual file system in detail.
The administrative user's home directory. Mind the difference between /, the root
/root
directory and /root, the home directory of the root user.
/sbin Programs for use by the system and the system administrator.
Temporary space for use by the system, cleaned upon reboot, so don't use this for
/tmp
saving any work!
/usr Programs, libraries, documentation etc. for all user-related programs.
Storage for all variable files and temporary files created by users, such as log files, the
/var mail queue, the print spooler area, space for temporary storage of files downloaded
from the Internet, or to keep an image of a CD before burning it.

Lab #1 – Linux filesystem structure, basic commands, getting help in the text environment.
Extra tools(tar, zip, unzip), editors(nano, vim, mcedit), text manipulation(grep, awk, sed, cut)
Page 3 of 8
Directories may vary from distribution to distribution. Actual structure for Oracle Enterprise Linux 6.6.

[4586][user@testmachine: /]$ tree / -L 1


/
|-- bin
|-- boot
|-- dev
|-- etc
|-- home
|-- lib
|-- lib64
|-- lost+found
|-- media
|-- mnt
|-- net
|-- nfs
|-- nsr
|-- opt
|-- proc
|-- root
|-- sbin
|-- selinux
|-- srv
|-- sys
|-- tmp
|-- usr
`-- var

23 directories, 0 files

Linux Command line


Simple version
1 [root@c006902 ~]# ls -lh
2 total 24K
3 -rw-------. 1 root root 1.2K Sep 30 12:00 anaconda-ks.cfg
4 -rw-rw-r--. 1 root mail 1.4K Feb 6 16:09 dead.letter
5 -rw-r--r--. 1 root root 1.2K Sep 30 12:00 initial-setup-ks.cfg
6 -rw-------. 1 root root 8 Nov 18 16:20 na01800280
7 drwxr-xr-x. 9 root root 4.0K Mar 5 15:06 rpmbuild
8 drwxr-xr-x. 3 root root 4.0K Jan 8 15:38 VirtualBox VMs
9 [root@c006902 ~]#

Line 1:
- root is the current logged in user on the machine (c006902)
- ~/ is the current working directory
- ls is the command, -lh are the arguments
Line 2 - 8 is the output of the command
Line 9 another prompt. After the ls command has been run, this prompt is waiting for another one.

Advanced version
1 [1015][na01800820@c006902: /home/na01800820]$
1015 is the history number of the command. Instead of ~/ the full path is displayed.

Lab #1 – Linux filesystem structure, basic commands, getting help in the text environment.
Extra tools(tar, zip, unzip), editors(nano, vim, mcedit), text manipulation(grep, awk, sed, cut)
Page 4 of 8
Opening a terminal
From a Windows machine a terminal can be opened via SSH/Telnet with putty. From a linux machines there are dozens
of terminal emulators(Terminator, Guake, Xterm etc).

The shell
What you type in the command line or scripts is executed by a shell which is called an interpretor. The most popular
interpretor is BASH (Bourbone again shell). Other shells are sh (older than bash), tcsh, ksh etc.
To see what shells you have installed on your machine:

1 [4532][user@testmachine: tmp]$ cat /etc/shells


2 /bin/sh
3 /bin/bash
4 /sbin/nologin
5 /bin/tcsh
6 /bin/csh
7 /bin/ksh

To see what shell you are currently using


1 [4534][user@testmachine: tmp]$ echo $SHELL
2 /bin/bash

Navigation
Where are we?
pwd will print the current working directory

1 [4535][user@testmachine: tmp]$ pwd


2 /tmp

ls will print a list of files in the current working directory

1 [4537][user@testmachine: tmp]$ ls
2 lost+found output rollout.sh sudoers

Paths
Relative paths are paths from the current point forward. Full paths are from the root directory(/) forward. Example:
The current working directory is /tmp/test which contains the test2 directory which contains a text file.

1 [4552][user@testsystem: test]$ ls
2 test2

This is the relative path:

1 [4553][user@testsystem: test]$ ls test2


2 test.txt

This is the full path

1 [4554][user@testsystem: test]$ ls /tmp/test/test2/


2 test.txt

More paths:

Lab #1 – Linux filesystem structure, basic commands, getting help in the text environment.
Extra tools(tar, zip, unzip), editors(nano, vim, mcedit), text manipulation(grep, awk, sed, cut)
Page 5 of 8
~ Is the shortcut for the home directory for the current logged in user. Example /home/student/Downloads can be used as
~/Downloads
. (dot) is the current working directory. We will talk later why is this useful.
.. (dotdot) is the previous directory(parent directory).

cd – is used to change the current working directory


Try to figure out what happened below

1 [4559][user@testsystem: test]$ cd ~/
2 [4560][user@testsystem: /nfs/home/user]$ pwd
3 /nfs/home/user
4 [4561][user@testsystem: /nfs/home/user]$ cd /tmp/test/test2
5 [4562][user@testsystem: test2]$ pwd
6 /tmp/test/test2
7 [4563][user@testsystem: test2]$ cd ..
8 [4564][user@testsystem: test]$ pwd
9 /tmp/test
10 [4565][user@testsystem: test]$ cd
11 [4566][user@testsystem: /nfs/home/user]$ pwd
12 /nfs/home/user

Basic commands
Linux ignores file extensions. So basicaly you can have a text file that ends in .txt.
file – is the command to find out what is actually that file.

This is an empty file

[4569][user@testsystem: /nfs/home/user]$ file /tmp/test/test2/test.txt


/tmp/test/test2/test.txt: empty

This is a file containing text

[4572][user@testsystem: /nfs/home/user]$ file /tmp/test/test2/test.exe


/tmp/test/test2/test.exe: ASCII text

This is a shell script

[4570][user@testsystem: /nfs/home/user]$ file /etc/init.d/sshd


/etc/init.d/sshd: Bourne-Again shell script text executable

This is a binary file

[4568][user@testsystem: /nfs/home/user]$ file /usr/bin/file


/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically
linked (uses shared libs), for GNU/Linux 2.6.18, stripped

cat – is used to print the content of a file on screen.

[4575][user@testsystem: /nfs/home/user]$ cat /tmp/test/test2/test.exe


This is test.exe

Lab #1 – Linux filesystem structure, basic commands, getting help in the text environment.
Extra tools(tar, zip, unzip), editors(nano, vim, mcedit), text manipulation(grep, awk, sed, cut)
Page 6 of 8
Files and folders
:>test.exe – can be used to create an empty file. We will see what :> actually means later.
mkdir – is used to create a directory
cp – is used to copy a file/folder
mv – is used to move a file/folder
rm – is used to delete a file/folder
rmdir – is used to delete a folder

Manual pages
To read the manual page for a command type
man <command>

Commands contain a lot of parameters which actually help you achive what you want on the screen more easly. It's
always advised to read at least once the manual page for all commands you use and test what the effect of diferent
arguments and parameters.
In theory all commands have a manual page, but it is the possibility of some 3rd party proprietary(non-free) software are
packaged non-LSB(Linux Standard Base) compliant.

File editors
Most popular file editors are vim, nano and mcedit.

Text manipulation
In linux, you have a powerful set of tools for text manipulations. This is very handy, among other uses, in parsing logs
and generating custom outputs.
grep – print lines matching a pattern
sed - stream editor for filtering and transforming text
awk - pattern scanning and processing language
cut - remove sections from each line of files
tr - translate or delete characters

Compression and archiving tools


tar - saves many files together into a single tape or disk archive, and can restore individual files from the archive.
zip - package and compress (archive) files
unzip - list, test and extract compressed files in a ZIP archive

Appendix
pwd
ls
cd
file
cat
mkdir
cp
mv
rm
rmdir
man
grep
sed
awk
cut

Lab #1 – Linux filesystem structure, basic commands, getting help in the text environment.
Extra tools(tar, zip, unzip), editors(nano, vim, mcedit), text manipulation(grep, awk, sed, cut)
Page 7 of 8
tr
cat

Links and notes


For home testing I recommand using VirtualBox and CentOS 6/7 (prefered is 6 because we will be running in the lab an
EL6 variant). Create a VM with 512 mb ram, 10gb hdd, single cpu is ok but will work better on a dual-core.

ftp://download.srv.ro/pub/centos/6/isos/x86_64/
https://www.virtualbox.org/

http://tldp.org/manpages/man.html - Offline manpages


http://www.tldp.org/
http://www.linux.com/learn/docs
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/
http://docs.oracle.com/cd/E37670_01/E41138/html/index.html

Lab #1 – Linux filesystem structure, basic commands, getting help in the text environment.
Extra tools(tar, zip, unzip), editors(nano, vim, mcedit), text manipulation(grep, awk, sed, cut)
Page 8 of 8

You might also like