Você está na página 1de 6

File Management commands.

Pwd - pwd command will print your home directory on screen, pwd means “print
working directory”.
/u0/ssb/sandeep - is output for the command when I use pwd in /u0/ssb/sandeep
directory.
Ls - ls command is most widely used command and it displays the contents of directory.
Options
• ls will list all the files in your home directory, this command has many options.
• ls -l will list all the file names, permissions, group, etc in long format.
• ls -a will list all the files including hidden files that start with . .
• ls -lt will list all files names based on the time of creation, newer files bring first.
• ls –Fx will list files and directory names will be followed by slash.
• ls –R will lists all the files and files in the all the directories, recursively.
• ls -R | more will list all the files and files in all the directories, one page at a time.

Mkdir - mkdir sandeep will create new directory, i.e. here sandeep directory is
created.

Cd - cd sandeep will change directory from current directory to sandeep directory.


Use pwd to check your current directory and ls to see if sandeep directory is there or not.
You can then use cd sandeep to change the directory to this new directory.

Cat - cat cal.txt cat command displays the contents of a file here cal.txt on screen (or
standard out).

More - More command will display a page at a time and then wait for input which is
spacebar. For example if you have a file which is 500 lines and you want to read it all. So
you can use

more filename

Wc - wc command counts the characters, words or lines in a file depending upon the
option.
Options
• wc -l filename will print total number of lines in a file.
• wc -w filename will print total number of words in a file.
• wc -c filename will print total number of characters in a file.

File -File command displays about the contents of a given file, whether it is a text
(Ascii) or binary file. To use it type
file filename. For example I have cal.txt which has ascii characters about calander of
current month and I have resume1.doc file which is a binary file in Microsoft Word. I
will get
file resume.doc
resume1.doc: data
file cal.txt
cal.txt: ascii text

Cp - cp command copies a file. If I want to copy a file named oldfile in a current


directory to a file named newfile in a current directory.
cp oldfile newfile
If I want to copy oldfile to other directory for example /tmp then
cp oldfile /tmp/newfile. Useful options available with cp are -p and -r . -p options
preserves the modification time and permissions, -r recursively copy a directory and its
files, duplicating the tree structure.

Rcp - rcp command will copy files between two unix systems and works just like cp
command (-p and -i options too).
For example you are on a unix system that is called Cheetah and want to copy a file
which is in current directory to a system that is called lion in /usr/john/ directory then you
can use rcp command
rcp filename lion:/usr/john
You will also need permissions between the two machines. For more infor type man rcp
at command line.

Mv - mv command is used to move a file from one directory to another directory or to


rename a file.
Some examples:
• mv oldfile newfile will rename oldfile to newfile.
• mv -i oldfile newfile for confirmation prompt.
• mv -f oldfile newfile will force the rename even if target file exists.
• mv * /usr/bajwa/ will move all the files in current directory to /usr/bajwa
directory.

Ln - Instead of copying you can also make links to existing files using ln command.
If you want to create a link to a file called coolfile in /usr/local/bin directory then you can
enter this command.
ln mycoolfile /usr/local/bin/coolfile
Some examples:
• ln -s fileone filetwo will create a symbolic link and can exist across machines.
• ln -n option will not overwrite existing files.
• ln -f will force the link to occur.
Rm - To delete files use rm command.
Options:
• rm oldfile will delete file named oldfile.
• rm -f option will remove write-protected files without prompting.
• rm -r option will delete the entire directory as well as all the subdirectories, very
dangerous command.

Rmdir - rmdir command will remove directory or directories if a directory is empty.


Options:
• rm -r directory_name will remove all files even if directory is not empty.
• rmdir sandeep is how you use it to remove sandeep directory.
• rmdir -p will remove directories and any parent directories that are empty.
• rmdir -s will suppress standard error messages caused by -p.

FILE TRANSFER B\W UNIX SYSTEMS

Ftp - ftp command is used to execute ftp protocol using which files are transferred over
two systems.
Syntax is
ftp options hostname
options
• -d enable debugging.
• -g disable filename globbing.
• -i turn off interactive prompts.
• -v verbose on. show all responses from remote server.

ftp hostname by default will connect you to the system, you must have a login id to be
able to transfer the files. Two types of files can be transferred, ASCII or Binary.

bin at ftp> prompt will set the transfer to binary.

Steps:
1. ftp hostname
2. Connects to host
3. Login:
4. Password:

Bin - Changes to binary mode. Note: You must do this!


get [filename] – copies file [filename] form host
mget [filespec] - Multiple files are copied from host.
put [filename] - copies file [filename] to host
mput [filenspec] - Multiple files are copied to host.
Bye – To disconnect from ftp
prompt - Turns off confirming uploads/downloads
hash - Turn on hash indicators for download/upload status
Advanced
Lcd - Changes your local directory (the directory from which you started 'ftp' from).
! - Allows to suspend ftp and use your command prompt, type 'exit' to return to 'ftp'.

Storage commands
Compress - compress command compresses a file and returns the original file
with .z extension, to uncompress this filename.Z file use uncompress filename command.
syntax for compress command is
compress options files
Options
• -bn limit the number of bits in coding to n.
• -c write to standard output (do not change files).
• -f compress conditionally, do not prompt before overwriting files.
• -v Print the resulting percentage of reduction for files.

Uncompress - uncompress file uncompresses a file and return it to its original


form.
syntax is
uncompress filename.Z this uncompresses the compressed file to its original name.
Options
• -c write to standard output without changing files

Cpio - cpio command is useful to backup the file systems. It copy file archives in from
or out to tape or disk, or to another location on the local machine. Its syntax is
cpio flags [options]
It has three flags, -i, -o, -p
• cpio -i [options] [patterns]
o cpio -i copy in files who names match selected patterns.
o If no pattern is used all files are copied in.
o It is used to write to a tape.
cpio -o
o Copy out a list of files whose name are given on standard output.
cpio -p
o copy files to another directory on the same system.
Options
o -a reset access times of input files.
o -A append files to an archive (must use with -o).
o -b swap bytes and half-words. Words are 4 bytes.
o -B block input or output using 5120 bytes per record.
o -c Read or write header information as Ascii character.
o -d create directories as needed.
o -l link files instead of copying.
o -o file direct output to a file.
o -r rename files interactively.
o -R ID reassign file ownership and group information to the user's login ID.
o -V print a dot for each file read or written.
o -s swap bytes.
o -S swap half bytes.
o -v print a list of filenames.
Examples
o find . -name "*.old" -print | cpio -ocvB > /dev/rst8 will backup all *.old
files to a tape in /dev/rst8
o cpio -icdv "save"" < /dev/rst8 will restore all files whose name contain
"save"
o find . -depth -print | cpio -padm /mydir will move a directory tree.

Dump command is useful to backup the file systems.


dump command copies all the files in filesystem that have been changed after a certain
date. It is good for incremental backups. This information about date is derived from
/var/adm/dumpdates and /etc/fstab .
syntax for HP-UX dump is
/usr/sbin/dump [option [argument ...] filesystem]

Options
• 0-9 This number is dump level. 0 option causes entire filesystem to be dumped.
• b blocking factor taken into argument.
• d density of tape default value is 1600.
• f place the dump on next argument file instead of tape.
• This example causes the entire file system (/mnt) to be dumped on
/dev/rmt/c0t0d0BEST and specifies that the density of the tape is 6250 BPI.
o /usr/sbin/dump 0df 6250 /dev/rmt/c0t0d0BEST /mnt
• for more info type man dump at command line.

Pack - pack command compacts each file and combine them together into a filename.z
file. The original file is replaced. Pcat and unpack will restore packed files to their
original form.
Syntax is
Pack options files
Options
• - Print number of times each byte is used, relative frequency and byte code.
• -f Force the pack even when disk space isn't saved.
• To display Packed files in a file use pcat command
pcat filename.z
• To unpack a packed file use unpack command as unpack filename.z .
Tar - tar command creates an archive of files into a single file.
Tar copies and restore files to a tape or any storage media. Synopsis of tar is
tar [options] [file]

Examples:
tar cvf /dev/rmt/0 /bin /usr/bin creates an archive of /bin and /usr/bin, and store on the
tape in /dev/rmt0.
tar tvf /dev/rmt0 will list the tape's content in a /dev/rmt0 drive.
tar cvf - 'find . -print' > backup.tar will creates an archive of current directory and store it
in file backup.tar.

Functions:
• c creates a new tape.
• r append files to a tape.
• t print the names of files if they are stored on the tape.
• x extract files from tape.

Options:
• b n use blocking factor of n.
• l print error messages about links not found.
• L follow symbolic links.
• v print function letter (x for extraction or a for archive) and name of files.

Mt - mt command is used for tape and other device functions like rewinding, ejecting,
etc. It give commands to tape device rather than tape itself. Mt command is BSD
command and is seldom found in system V unix versions.
syntax is
mt [-t tapename] command [count]
mt for HP-UX accept following commands

• eof write count EOF marks.


• fsf Forward space count files.
• fsr Forward space count records.
• bsf Backward space count files.
• bsr Backward space count records.
• rew Rewind tape.
• offl Rewind tape and go offline.
• eod Seek to end of data (DDS and QIC drives only).
• smk Write count setmarks (DDS drives only).
• fss Forward space count setmarks (DDS drives only).
• bss Backward space count setmarks (DDS drives only).
• Examples
o mt -t /dev/rmt/0mnb rew will rewind the tape in this device.
o mt -t /dev/rmt/0mnb offl will eject the tape in this device.

Você também pode gostar