Anda di halaman 1dari 35

Basic Linux Commands

Outline
Very Basic Commands Working with Files File Redirection Getting Help File Permissions Links Editors Remote Login

Server and Desktop Differences


There are a few differences between the Ubuntu Server Edition and the Ubuntu Desktop Edition. both editions use the same apt repositories. The differences between the two editions are the lack of an X window environment in the Server Edition, the installation process, and different Kernel options.

Cont
During the Server Edition installation you have the option of installing additional packages from the CD. The packages are grouped by the type of service they provide. Example DNS server: Selects the BIND DNS server and its documentation.

Very Basic Commands

Listing Files and Directories


ls (list) - Lists directory contents ls [option] [file]
% ls list files in the current directory % ls /etc list content of /etc directory % ls a list all files (including hidden files) % ls l use long listing format when displaying the list

Creating Directories
mkdir (make directory) Syntax: mkdir [options] directoryname %mkdir Juict
create the directory JU in the current directory

%mkdir /home/juict2 Create the directory juict2 in the /home directory

Changing to a Different Directory


cd (change directory) Syntax: cd directoryname
Change the current working directory to 'directory'.

cd ..
change to parent directory)

Example:
% cd juict
Change to the directory bmo

% cd /home/juict2

Path Names
pwd (print name of current/working directory) Syntax: pwd [options] Example: %pwd

Summary of very basic commands


ls ls -a mkdir cd directory cd cd ~ cd .. pwd list files and directories list all files and directories make a directory change to named directory change to home-directory change to home-directory change to parent directory display the path of the current directory

Working with Files

Copying Files
Syntax: cp [option] source destination
Copy the file Source to Destination

Example:
%cp file1 /home/juict2 copy the file file1 to the directory /home/juict2 %cp r /home/juict2 juict copy the directory (with all its file) /home/juict2 to the directory juict

%cp /home/juict2/file1 copy the file file1 from the directory /home/juict2 to the current directory

Moving/renaming Files
Syntax: mv [option] source destination Example: %mv file1 flie2
Renames the file file1 to file2( If you move it with in the same directory giving it different name it actually renames the file)

%mv /home/juict/ file1 juict/file2


Move the file file1 from /home/juict directory to juict directory

%mv -r /home/juict /tmp


Move the folder juict in /home/ directory to /tmp directory

Removing Files and Directories


rm - remove files and directories
Syntax: rm [Option] File Example:
% rm juict/file1 remove the file file1 from the directory bmo % rm r /home/juict2 delete the directory /home/juict2 along with its files

rmdir - remove empty directory


Syntax: rmdir [Option] directory Example:
%rmdir juict delete the empty directory juict

Displaying Content of Files on Screen


cat - concatenate files and print on std output
Syntax: cat [option] [file] Example:

% cat file1 display the content of file1 on the screen less


Syntax: less [option] file Example:
Less file1

Displaying
more
Syntax: more [option] file Example:
more file1

tail
Syntax: tail [option] file Example:
tail file1

Searching the contents of a file


grep print lines matching a pattern Syntax: grep [options] pattern [file] Example: search for the word localhost in the file /etc/hosts
grep localhost /etc/hosts (Use i option to ignore case)

Simple searching using less Use the less command to display the content of the file and then type /searchstring Example: (search for the word localhost in the file /etc/hosts) % less /etc/hosts /localhost

Summary Working with files


cp file1 file2 mv file1 file2 rm file rmdir directory cat file more file head file tail file grep 'keyword' file
copy file1 and call it file2
move or rename file1 to file2

remove a file
remove a directory display a file display a file a page at a time display the first few lines of a file display the last few lines of a file search a file for keywords

File Redirection

Pipe
Use the pipe (|) symbol to give the output of one command as an input to another command. Example
%ls /etc | grep resolv.conf (list the content of the file /etc and display lines containing the name resolv.conf)

Summary - Redirection
command > file command >> file command < file
redirect standard output to a file
append standard output to a file redirect standard input from a file pipe the output of command1 to

command1 | command2 the input of command2 cat file1 file2 > file0

concatenate file1 and file2 to file0

File Permissions
The long version of a file listing (ls -l) will display the file permissions:
-rwxrwxr-x -rw-rw-r--rw-rw-r-drwxrwxr-x 1 1 1 7 rvdheij rvdheij rvdheij rvdheij rvdheij rvdheij rvdheij rvdheij 5224 221 1514 1024 Dec Dec Dec Dec 30 30 30 31 03:22 03:59 03:59 14:52 hello hello.c hello.s posixuft

Permissions

Group

Owner
September 3, 2012 Jimma University ICTDO 22

Interpreting File Permissions

-rwxrwxrwx
Other permissions Group permissions Owner permissions Directory flag (d=directory; l=link)

September 3, 2012

Jimma University ICTDO

23

Changing File Permissions


Use the chmod command to change file permissions
The permissions are encoded as an octal number
chmod 755 file # Owner=rwx Group=r-x Other=r-x chmod 500 file2 # Owner=r-x Group=--- Other=--chmod 644 file3 # Owner=rw- Group=r-- Other=r-chmod +x file chmod o-r file chmod a+w file
September 3, 2012

# Add execute permission to file for all # Remove read permission for others # Add write permission for everyone
Jimma University ICTDO 24

Editors
People are fanatical about their editor Several choices available:
vi Standard UNIX editor gedit graphical text editor nano Simple display-oriented text editor Pico Simple display-oriented text editor

September 3, 2012

Jimma University ICTDO

25

Remote login
ssh user@server
Provide password for user to login.
scp: source destination
Copy files from one computer to another Source and destination are files on different computers

telnet server
login with telnet session
26

Getting Help
On-line Manuals Syntax: man command Example:
% man ls Shows manual entry for the command ls

Package Management
Apt-Get The apt-get command is a powerful command line tool used to work with Ubuntu's Advanced Packaging Tool (APT) performing such functions as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire Ubuntu system.

Some examples of popular uses for the apt-get utility:


Install package: sudo apt-get install squid Remove package: sudo apt-get remove Remove package with package configuration files : sudo apt-get purge remove squid Update the Package:sudo apt-get update Upgrade the Package:sudo apt-get upgrade

dpkg
dpkg is a package manager for Debian based systems. It can install, remove, and build packages, but unlike other package management system's it can not automatically download and install packages and their dependencies. This section covers using dpkg to manage locally installed packages: To list all packages installed on the system, from a terminal prompt enter: dpkg -l

Cont
You can install a local .deb file by entering: sudo dpkg -i zip_2.32-1_i386.deb Change zip_2.32-1_i386.deb to the actual file name of the local .deb file. Uninstalling a package can be accomplished by: sudo dpkg -r zip Uninstalling packages using dpkg, in most cases, is NOT recommended. It is better to use a package manager that handles dependencies,

Cont
To list the files installed by a package, in this case the ufw package, enter: dpkg -L ufw If you are not sure which package installed a file, dpkg -S may be able to tell you. For example: dpkg -S /etc/host.conf base-files: /etc/host.conf The output shows that the /etc/host.conf belongs to the base-files package.

Networking
auto eth0 iface eth0 inet static address 10.0.0.100 netmask 255.255.255.0 Networking gateway 10.0.0.1

Adding and Deleting user


To add a user account sudo adduser username To delete a user account and its primary group, use the following syntax: sudo deluser username

Thank You

Anda mungkin juga menyukai