White Hat Institute

Linux basics

Command-line interface (part 2)

Manipulating with files

In this section, we will show a few frequently used commands for file and directory manipulation. These commands are; “cp,” “mv,” “rm,” “touch,” and “file.”

  • “cp”copy: The “cp” option duplicates records or directories.

            Ex: ([email protected]:~/Downloads$ cp Text.txt1 Text.txt2)

Linux basics 10

You can likewise utilize “cp” to duplicate various records into a directory. For this situation, the last argument must be a directory.

Ex: ([email protected]:~/Downloads$ cp Text.txt1 InfoSec/Text.txt2)

Linux basics 10

To copy everything in the directory, use the “-r” operator. The “-r” option forces recursive duplicating of all records in all sub-directories.

Ex: ([email protected]:~/Downloads$ cp -r InfoSec/ Security)

Linux basics 12
  • “mv”move: The “mv” option performs both record moving and document renaming, contingent upon how it is utilized. In either case, the first filename never again exists after the activity. “mv” is used similarly as “cp.”

           Ex: ([email protected]:~/Downloads$ mv Text.txt1 HelloWorld)

Linux basics 13
  • “rm”remove: The “rm” command is utilized to erase documents and directories.

            Ex: ([email protected]:~/Downloads$ rm HelloWorld)

Linux basics 14

Before erasing a current document, you can use “-i” (for interactive) option to brief the user for affirmation. If, in any case, this option isn’t determined, the “rm” command will quietly erase records.

Ex: ([email protected]:~/Downloads$ rm -i Text.txt2)

Linux basics 15

If you want to delete everything in the directory, you need to specify the “-r” (for recursive) option.

Ex: ([email protected]:~/Downloads$ rm -r InfoSec/)

Linux basics 16
  • “file”: The “file” operator decides the record type. Linux doesn’t utilize augmentations to determine the document type. The command line does not care whether a file ends in “.txt” or “.pdf.” As a security analyst, you should use the “file” option to determine the document type.

           Ex: ([email protected]:~/Downloads$ file Security_Report)

Linux basics 17
  • “touch”: To create a new empty file in Linux operating systems, we use the “touch” option.

           Ex: ([email protected]:~/Downloads$ touch HelloWorld)

Linux basics 18