Latest topics
Talagang Temperature
Advertisment

Log in

I forgot my password

Who is online?
In total there are 12 users online :: 0 Registered, 0 Hidden and 12 Guests :: 2 Bots

None

[ View the whole list ]


Most users ever online was 145 on Wed Mar 02, 2011 2:26 am

Linux Basic Commands

View previous topic View next topic Go down

Linux Basic Commands

Post by Shehla Ali on Wed May 11, 2011 6:57 pm

Linux Basic Commands

Files Commands

ls : The command ls is used to list the contents of a directory.

Examples:-

ls -l long listing
ls -R list current directory and all other directories within current directory
ls -a list hidden files
ls -CF list in column format and append '*' to executable files, '@' to symbolic linked files, '/' to directories
ls -r list in reverse alphabetically order
ls -t list more recent accessed files first
ls -lrt List files by date

You Can Wildcard characters with ls command

* asterisk symbol is used to represent anycharacter
? question mark is used to represent any single character
(from-to) Values entered within brackets represent a range for a single character
(!from-to) Values entered within brackets represent a range to exclude for a single character

cd - : Go to previous directory

cp : To copy files

Examples:-

will copy f1 to f2 if f2 doesnot exist, it will be created, but if it exists, it will be overwritten

$ cp f1 f2

If you want to copy file into directory testdir:

$ cp f1 testdir

Option i is basaically used as an ["interactive"] with cp command

$ cp -i f1 f2
cp: overwrite `f2'? n

Other options are with cp command

-f [force] if an existing destination file cannot be opened, remove it and try again
-l [link] links files it will not copy.
-p [preserve=mode],ownership,timestamps
-R, -r,[recursive] copy directories recursively
-s [symbolic-link] make symbolic links instead of copying
-v [verbose] mode

rm : Delete files

Examples:-

rm f1 remove the file 'f1'
rm -i f* prompt to remove each file in current directory starting with letter 'f'
rm xyz* remove all files in current directory starting with letter 'xyz' without prompt

mv: command can be used for moving or renaming files

Examples:-

To rename file you can use this command

$ mv f1 f2

To move the f1 into [dir1]another directory

$ mv f1 dir1

You can use following option with this command

-f ,[force] prompt before overwriting
-i ,[interactive] prompt before overwrite
-S ,[suffix=SUFFIX]
-u ,[update] move only when the SOURCE file is newer than the destination file or when the destination file is missing

rm: Is used for removing files and directories.

Examples:-

To remove a file f1

$ rm f1

you'll be prompted before removing the file when you will use i option:

$ rm -i f1

deleting more files with single command:

rm f1 f2

Directory Navigation Command

cd - : Go to previous directory

cd : Go to home directory

mkdir : Making Directory in linux

mkdir [options] directories

OPTIONS:

-m :Set the access mode for the new directories.
-p :Create intervening parent directories if they don't exist.
-v :Print help message for each directory created.

tar: command is used to create archive and extract the archive files.

SYNTAX:

tar [options] [archive-file] [File or directory to be archived]

OPTIONS:
-c : Creates Archive
-x : Extract the archive
-f : creates archive with give filename
-t : displays or lists files in archived file
-u : archives and adds to an existing archive file
-v : Displays Verbose Information
-A : Concatenates the archive files

Example:-

tar-vxf my_file.tar

tar: the command
vxf: the options
v: provides a description of the unpacked files(optional)
x: to extract the files
f: to designate the archive containing the files (given parameter)
my_file.tar: the name of the archive to retrieve

The gzip and gunzip Commands

The gzip program compresses a single file. One important thing to remember about gzip is that, unlike tar, it replaces your original file with a compressed version

Examples

gzip f1.txt

In the above example command this would compress the f1.txt file as f1.txt.gz in the current directory.

gunzip f1.txt.gz

In the above example command it would extract the f1.txt from f1.txt.gz.

The bzip2 command is used for compressing and decompressing files.

Data compression, also referred to as just compression, is the process of encoding data using fewer bits.

Example:-

tar -cf file7.tar file4 file5 file6
bzip2 file7.tar
Disk Spacing Commands

ls -lSr Show files by size, biggest last
df -h Show free space on mounted filesystems
df -i Show free inodes on mounted filesystems
fdisk -l Show disks partitions sizes and types (run as root)

Mounting Devices and File System

you can store your data in different physical storage devices, like floppies, CD-ROMs, and hard disk drives.
Your hard disk or disks are also very likely split up into different partitions with different filesystems.

mount: mount a file system or devices
umount : Unmount file system or devices
Examples:-

Mounting Floppy Drive
$ mount /dev/fd0 /mnt/floppy

Mounting CD-ROM Drive
$ mount /dev/cdrom /mnt/cdromdrive

umount : Unmounting the file system.

Examples:-

Umounting Floppy Drive
umount /mnt/floppy

Umounting CD-Rom Drive
umount /mnt/cdrom

Mounting Windows File system
mount /dev/hda1 /mnt/windows vfat user 0 0

To make set the Windows partition to be mounted every time the system starts, the /etc/fstab entry would be like the following:

mount /dev/hda1 /mnt/windows vfat auto,user 0 0

Mounting SATA Drive

mount -t ntfs /dev/sda1 /mnt/drive_windows

Mounting Windows Xp/Vista/7 file system in Linux


mount /dev/sda5 /mnt/shared32 vfat auto,umask=0 0 0

find :- command is use to search file in the system(linux or unix)

Example:-

find /home -user sweety
Find every file under the directory /home owned by the user sweety.

find /usr -name *end
Find every file under the directory /usr ending in ".end".

find /home/software -mtime +60
Find every file under the directory /home/software that was modified more than 60 days ago.

User account creation command

userdel -r for delete a user

passwd for passwd a user

adduser login_name adding user

useradd -m login_name Most of the Suse enviourment

passwd login_name you need to give the new user a password for the new account

useradd add New User

linux User and permission

In Linux there are following permission you can give to user to access file or folder

read(r), write(w) ,execute(x), all(a).

execute=1 , write=2 , read=4

In linux there are following type of users

user(u) , group(g) , others(o)

Example:-

Giving all permission to arun

all (=user+group+others):

chmod a+r arun

will remove the permission to execute the file "arun" from others

chmod o-x arun

The permission for all three catagories of users (owner, group, others) is obtained by inserting the three digits together one by one.

chmod 770 arun
__________________________________

_________________

Shehla Ali
Administrator
Administrator

Female Number of posts: 7666
Location: United Kingdom, Manchester
Job/hobbies: Reading Poetry, Writing,Music
Reputation: 55
Points: 13025
Registration date: 2009-01-14

View user profile

Back to top Go down

View previous topic View next topic Back to top


Permissions in this forum:
You cannot reply to topics in this forum