Skip to main content

Unix Commands Part 2

File Management commands.

cat,cd, cp, file,head,tail, ln,ls,mkdir ,more,mv, pwd, rcp,rm, rmdir, wc.


Pwd command.
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 command
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 -Fxwill list files and directory names will be followed by slash.
  • ls -Rwill 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 command.
mkdir sandeep will create new directory, i.e. here sandeep directory is created.


Cd command.
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 command
cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).


Head command.
head filename by default will display the first 10 lines of a file.
If you want first 50 lines you can use head -50 filename or for 37 lines head -37 filename and so forth.


Tail command.
tail filename by default will display the last 10 lines of a file.
If you want last 50 lines then you can use tail -50 filename.


More command. 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 command
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 command.
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 binariy file in microsoft word. I will get
file resume.doc

resume1.doc:    data   
file cal.txt
cal.txt:        ascii text

Cp command.
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 command.
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 command.
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 command.
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 command.
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 command.
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.


Comments

Popular posts from this blog

INSTALL CISCO VPN CLIENT ON WINDOWS 10 (32 & 64 BIT). FIX REASON 442

This article shows how correctly install Cisco VPN Client (32 & 64 bit) on Windows 10 (32 & 64 bit) using simple steps, overcome the ‘ This app can’t run on this PC ’ installation error , plus fix the Reason 442: Failed to enable Virtual Adapter error message . The article applies to New Windows 10 installations or Upgrades from earlier Windows versions and all versions before or after Windows 10 build 1511 .  To simplify the article, we’ve broken it into the following two sections: How to Install Cisco VPN client on Windows 10 (clean installation or upgrade from previous Windows), including Windows 10 build prior or after build 1511 . How to Fix Reason 442: Failed to enable Virtual Adapter on Windows 10 Figure 1. The Cisco VPN Client Reason 442: Failed to enable Virtual Adapter error on Windows 10 HOW TO INSTALL CISCO VPN CLIENT ON WINDOWS 10 (NEW INSTALLATIONS OR O/S UPGRADES) The instructions below are for new or clean Windows 10 inst...

Linux File and Directory Permissions

file & directory protection is a essential of any OS and Linux OS is no exception for it! These authorizations allow you to choose exactly who can access your files & directory, providing an overall improved system security. There was one of the major flaws in the older Windows operating-system where, by standard, all users can see each other people's information (Windows 95, 98, Me). For overcoming it, editions of the Windows based computer system such as NT, 2000, XP and 2003 lot more security features added. They fully support file & directory permissions, just as Linux system has since the beginning. Together, we'll now assess a directory listing from our Lab Linux system hosting server, to help us understand the information provided. a simple 'ls' command will give you the file and directory listing within a given directory, including the option  '-l' will display number of new areas that we are going to discuss here:

How to create a Hirens Boot CD 15.2 USB Disk

Hiren’s BootCD (HBCD) is a bootable CD that contains a set of tools that can help users to fix their computer if their system fails to boot. More specifically, HBCD contains hardware diagnostic programs, partition tools, data recovery utilities, antivirus tools and many other tools to fix your computer problems.  I write this article because I use Hiren’s BootCD frequently to troubleshoot computer problems, specially when a computer doesn’t boot anymore due to a virus attack or due to a corrupted file system. In this article you will find instructions on how to put Hiren’s BootCD on a USB flash drive (stick) in order to troubleshoot computer problems in the future.