Tutorials Hut

  • Unix For Testers

       Introduction to Unix
       Unix System Architecture
       Unix File System Structure
       Absolute and Relative Path
       Basic Unix Commands
       cal command in Unix
       who command in Unix
       date command in Unix
       clear command in Unix
       more command in Unix
       whoami command in Unix
       uname command in Unix
       man command in Unix
       echo command in Unix
       Unix File System Commands
       ls command in Unix
       cat command in Unix
       cp command in Unix
       mv command in Unix
       pwd command in Unix
       cd command in Unix
       mkdir command in Unix
       rmdir command in Unix
       rm command in Unix
       touch command in Unix
       dirname command in Unix
       tar command in Unix
       Unix Links(ln)
       Hard Link
       Soft Link
       Regular Expressions
        Basic Regular Expressions
       Interval Regular Expressions
       Pipes and Filters
       Unix Text Processing Commands
       cmp command in Unix
       diff command in Unix
       comm command in Unix
       cut command in Unix
       Paste command in Unix
       head command in Unix
       tail command in Unix
       wc command in Unix
       sort command in Unix
       grep command in Unix
       Process Related Command
       top command in Unix
       ps command in Unix
       nice command in Unix
       Kill command in Unix
       nohup command in Unix
       time command in Unix
       File Tranfer Commands in Unix
       file transfer using scp command
       file transfer using rlogin command
       file transfer using telnet command
       ssh(Secure Shell) command in Unix
       ftp file transfer command
       sftp file transfer command
       chmod command in Unix
       File Permission and File Security in Unix



  • File System Commands in Unix: ls, cat, cp, mv, pwd, cd, mkdir, rmdir, touch, dirname, tar

    This article aims to familiarize with the basic file system commands in Unix that helps to work with files and directories.  ls command in Unix, cat command in Unix, cp command in Unix, mv command in Unix, pwd command in Unix, cd command in Unix, mkdir command in Unix, rmdir command in Unix, touch command in Unix,dirname command in Unix, tar command in Unix etc. are some of the commonly used File System commands in Unix.

    In this article we will discuss about below Unix commands:

    ls command in Unix

    It is a command line utility that lists the content/files listed in a particular Unix directory. ls command with no parameters the command displays the files listed in your current working directory. With ls command, you can add one or more modifiers to get additional information.

      • List contents of a directory 
      • ls is a command to list computer files in Unix
      Syntax:
     ls [option] [filenames]
    Command Use
    ls -a 
    Displays all files including hidden files
    ls -l
    Long listing- The default output of the ls command shows only the names of the files and directories. The -l option shows files in a long listing format with details like file type, file permissions,Number of hard links to the file,file owner, file group, file size, Date and Time, file name.
    ls -i
    Displays list of directory contents with inode number
    ls -r
    Lists directory contents in reverse order.
    ls -t
    Sort the data by modification date

    Here is an example:

    ls -l /etc/hosts
    -rw-r--r-- 1 root root 317 Dec  4 11:31 /etc/hosts

        cat command in Unix

    The cat (“concatenate“) command is one of the most frequently used command in Unix. cat command allows us to create single or multiple files, view content of file, concatenate files and redirect output in terminal or files.

      • Concatenate and display files 
      • It reads data from the file and gives their content as output. 
    Syntax:
    cat [option...] [file ...]
    Command Description
    $ cat filename

    To view a single file.

    It will show content of given filename

    $ cat file1 file2

    View multiple files.

    Shows the content of file1 and file2.

    $ cat -n filename
    Shows contents of a file preceding with line numbers
    $ cat > new1
    Create file named new1
    $ cat [sourceFile] > [destFile]

    Copy the contents of one file to another file.

    The content will be copied to the destination file.

    $ cat -s filename
    Suppress repeated empty lines from the file.
    $ cat file1 >> file2
    Append the contents of one file to the end of another file
    $ cat "file1" "file2" "file3" > "mergedFile"
    Merge the contents of multiple files

    Examples of the cat command in Unix are:

    1. Create a File with cat Command

    Create a File with cat Command

    2. Copy Content of a file to another with cat Command and view the file

    Unix: Copy Content of a file to another with cat Command

    cp command in Unix

    Unix command used to copy files and directories

        • Copy files 
        • It creates an exact image of a file on a disk with a different name.
    Syntax:
    cp [option] [file1] [file2]

    command contains two file names, copies the contents of  file1 to the  file2. If the 2nd file doesn’t exist, then first it creates one and then content is copied to it.

    cp [option] [file1] [file2][directory]

    Command copies file1 and file2 to directory 

         Examples of the cat command in Unix are:

    make directory dir1 using mkdir command

    Copy test1 and test2 files into this directory.

    Change to dir1 using cd command

    Check directory dir1 content

    Unix: copy files to directory with cp command

    mv command in Unix

    mv command in Unix is used to move files or directories from one place to another.

          • Move or rename files 
          • mv is used to move one or more files or directories from one place to another.
    Syntax:
    mv [option] [sourceFile] [destFile]

    If the destination file doesn’t exist, it will be created.

    If the destination file exist, then it will be overwrite and the source file will be deleted

         pwd command in Unix

    Displays the present working directory

    Syntax:
    pwd

         cd command in Unix

    Change Working directory or change the current working to some other folder.

    Syntax:

    Command

    Description

    $cd ./myData

    Change current directory to myData

    $cd ..

    Change current directory to parent directory

    $cd /home/base/myData

    Change current directory to dir1

    $cd - 

    Changes to last directory (from where you came) 

    Can be used to toggle between two directories

    $cd

    Changes to user’s home directory 

    Home directory is referred by ~ character

       

    Example of  cd command in Unix are:

    change directory from home(~) to mydata

    change directory to parent directory using cd..

    Change to home directory using cd command

    Unix:change directory with cd command

     mkdir command in Unix

          • Create new directories
    Syntax:
     mkdir [options] DirectoryNames

      rmdir command in Unix

          • Remove directories
    Syntax:
    rmdir [options] DirectoryNames

         rm command in Unix

          • Remove files or directories .For more details on this click here 
    Syntax:
     rm [option...] filelist
     
     
    Recommended Articles:



  • Unix For Testers

       Introduction to Unix
       Unix System Architecture
       Unix File System Structure
       Absolute and Relative Path
       Basic Unix Commands
       cal command in Unix
       who command in Unix
       date command in Unix
       clear command in Unix
       more command in Unix
       whoami command in Unix
       uname command in Unix
       man command in Unix
       echo command in Unix
       Unix File System Commands
       ls command in Unix
       cat command in Unix
       cp command in Unix
       mv command in Unix
       pwd command in Unix
       cd command in Unix
       mkdir command in Unix
       rmdir command in Unix
       rm command in Unix
       touch command in Unix
       dirname command in Unix
       tar command in Unix
       Unix Links(ln)
       Hard Link
       Soft Link
       Regular Expressions
        Basic Regular Expressions
       Interval Regular Expressions
       Pipes and Filters
       Unix Text Processing Commands
       cmp command in Unix
       diff command in Unix
       comm command in Unix
       cut command in Unix
       Paste command in Unix
       head command in Unix
       tail command in Unix
       wc command in Unix
       sort command in Unix
       grep command in Unix
       Process Related Command
       top command in Unix
       ps command in Unix
       nice command in Unix
       Kill command in Unix
       nohup command in Unix
       time command in Unix
       File Tranfer Commands in Unix
       file transfer using scp command
       file transfer using rlogin command
       file transfer using telnet command
       ssh(Secure Shell) command in Unix
       ftp file transfer command
       sftp file transfer command
       chmod command in Unix
       File Permission and File Security in Unix

















  • Leave a Reply

    Your email address will not be published. Required fields are marked *