Top Banner
BASIC LINUX COMMANDS Welcome to the Linux World
32

Basic linux commands

Jul 09, 2015

Download

Software

Shakeel Shafiq

Basic Commands for BioInformatics Students
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Basic linux commands

BASIC LINUX COMMANDS

Welcome to the Linux World

Page 2: Basic linux commands

What are linux commands

Linux commands are just simple programs like a program in windows. Typing command is like clicking an icon in windows.

Sometimes commands take some extra parameters to do extra work, we call them flags.

Page 3: Basic linux commands

man (Your best friend!)

man means manual pages, its like reading a manual of any home appliance. In software it means reading documentation. Good softwares have always a good documentation part.

$ man <command>$ man clear

Page 4: Basic linux commands

ls (list items)

● The ls command ( lowercase L and lowercase S ) lists the contents of your current working directory.

● ls by default does not show hidden files

● to see all files use ls -al● -al is flag in this case

Page 5: Basic linux commands

mkdir (make directory)

● creates a directory● use -p to create as many directories.● $ mkdir first/second/third -p● $ cd first/second/third

Page 6: Basic linux commands

cd (change directory)

● changes the current directory ● cd . to remain inside same directory● cd .. to go back one directory

Page 7: Basic linux commands

pwd (print working directory)

For example, to find out the absolute pathname of your home-directory, type cd to get back to your home-directory and then type

$ pwdit will print current directory

Page 8: Basic linux commands

~ Your Home Directory

By typing cd ~ in terminal it will take you to the home directory of current user$ cd ~

Page 9: Basic linux commands

cp (copy)

copies a file or entire directory to another pathIf you want to copy files from another directory to current directory use a . for destination$ cp <source_file> <destination_file>Tip: Always read the error carefully and please don't freak out :)

Page 10: Basic linux commands

mv (move file)

move command renames or move a file

use -r flag to recursively move all files

$ mv file1.txt file2.txt

Page 11: Basic linux commands

rm (remove)

rm removes a file or entire directory with -r flag

$ rm <file>$ rm <directory> -r

Page 12: Basic linux commands

clear

clears your screen

$ clear

Page 13: Basic linux commands

cat

displays the content of files on screen.

$ cat file.txt

Page 14: Basic linux commands

less

Iess is similar to cat but it displays content one page at a time

$ less file.txt

Page 15: Basic linux commands

head

head is a short version of less command. It prints only first 10 lines.

You can set the number of lines by giving a -<number> flag e.x$ head -5 file.txt

Page 16: Basic linux commands

tail

tail is opposite to head, it shows last 10 lines of the file.

Page 17: Basic linux commands

searching within text

You can use less command to search within text. Do you remember what less command do?After executing the less command use / and type your required text to search$ less file.txt/science

Page 18: Basic linux commands

grep (don't ask what that’s called :) )

This command search a file for specific word or a pattern. for examplegrep Science file.txt will search string Science in file.txt

grep command by default is case sensitive

Page 19: Basic linux commands

wc (word count)

counts number of words in a given file.

to find number of lines set the -l flag

$ wc -l file.txt

Page 20: Basic linux commands

Writing input to output

type the cat command without file name. It will start taking your text into output memory. Once you press Ctrl + d the output will be printed on screen.$ cat$ alpha $ Ctrl + d

Page 21: Basic linux commands

use cat to write a file

$ cat > file.txtThis will take your input and write to a file by name file.txt from your input until Ctrl+d is pressed.

Page 22: Basic linux commands

Pipes

Piping means passing result of one command to another command.

You can search in first 10 lines by using head and grep command by piping$ head file.txt | grep science

Page 23: Basic linux commands

The wildcard *

The * character is a wildcard character. It means it will ignore the part after and before where its used$ ls list*will list all files starting with string list$ ls *listwill list all files ending with string list

Page 24: Basic linux commands

UNIX File System

Type ls -l and see the result

Page 25: Basic linux commands

UNIX File SystemIn the left-hand column is a 10 symbol string consisting of the symbols d, r, w, x, -, and,

occasionally, s or S. If d is present, it will be at the left hand end of the string, and indicates a

directory: otherwise - will be the starting symbol of the string.

The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of

3.

● The left group of 3 gives the file permissions for the user that owns the file (or directory) (thirdknife in the above example);

● the middle group gives the permissions for the group of people to whom the file (or directory) belongs (staff in the above example);

● the rightmost group gives the permissions for all others.The symbols r, w, etc., have slightly different meanings depending on whether they refer to a simple

file or to a directory.

Page 26: Basic linux commands

chmod (changing file mode)

Only owner can change the mode.Symbol Meaning

u user

g group

o other

a all

Page 27: Basic linux commands

chmod (changing file mode)Symbol Meaning

r read

w write (and delete)

x execute (and access directory)

+ add permission

- remove permission

Page 28: Basic linux commands

Example

$ chmod a+rw file.txtthis will give read and write access to all user, group and others

-rwxrwxrwx 1 thirdknife staff 5 Nov 27 23:09 text.txt

Page 29: Basic linux commands

making file executable and runnable

For any file to be executable you have to make it x using chmod, e.g$ chmod a+x file.txt this will make file.txt executable for all (user, group and others)to execute a file use ./<filename>

Page 30: Basic linux commands

sudo (execute commands as others)

Use this command to do as a different user.

$sudo su lswill list files as root user $sudo su - shakeel ls will list files as shakeel user

Page 31: Basic linux commands

Tips

Always use manual pages for help.I understand they are boring but believe me thats where I learned the most. Second friend is google :)

Try to understand the error statement.

Page 32: Basic linux commands

Contact

[email protected]