So now we have learned how to move around the terminal in the previous post. Let’s move onto manipulating files and folders. We will focus on the following commands, which I believe are the ones you will use the most on your hacking adventures.

  1. mkdir (Make Directory)
  2. touch (Create a file)
  3. mv (Move a File/Folder)
  4. cp (Copy a File/Folder)
  5. rm (Remove a File)
  6. rmdir (Remove a Folder)
  7. nautilus (File Explorer)

Let’s start…

MKDIR (Make a Directory)

Straight forward, a command to make a directory. If you type ‘mkdir somefolder’ it will create the folder name of choice, in the directory you are within.

A very useful switch to know for this command is the ‘-p’ option, useful for bash scripts in particular. If you need to make the parent directories of a given path. Let’s say we need to make the following folder paths ‘mkdir -p folder1/subfolder/anothersubfolder/’. It will create the ‘subfolder’ and ‘anothersubfolder’, folders.

Let’s see if we can change the directory to the folder we just created.

Would you look at that.

TOUCH (Create a file)

The appropriately named ‘touch’ command. This will give us an empty file we can then do something with. This command does come packaged with many arguments, if you check out the man page. However I can’t say I have ever used them. Type ‘touch file4.

The file is now touched.

MV (Move a File/Folder)

The move command can be used on files as well as folders. Let’s create a new folder, using ‘mkdir letsmovesomething’ and then move our files.

Now move all of the files, file (1-4) into the ‘letsmovesomething’ folder. (Note that we are using a wildcard *).

Great now ls the letsmovesomething folder.

Awesome all the files have moved. I won’t bore you with the same concept with the folders, it’s the same process.

CP (Copy a File/Folder)

The copy command is as it sounds, it will copy the contents of the file or folder. Let’s use the touch command to create a new file to copy. ‘touch copyme’.

Now copy the file into ‘folder1’, ls the current directory, then ls the folder1 directory.

As you can see, the file has been copied.

RM (Remove a File)

We have made an awful mess with all of these random files. Let’s get rid of a few of them to make room for more random files. Since we moved all the ‘file’ files into the ‘letsmovesomething’ folder. Let’s empty it using a wildcard. First cd into ‘letsmovesomething’ and list the contents.

Now remove everything with the wildcard *.


RMDIR (Remove a Folder)

Swiftly moving on. The same concept applies to moving a folder, we will make this quick. Remote the letsmovesomething folder, you might need to move back a level first using ‘cd ..’

You guessed it, it’s gone.

NAUTILUS (File Explorer)

This is my favorite little trick when I am not prepared to string commands together to edit, remove and copy files. I just use nautilus instead, which will open the file explorer. You can either specify a directory, or if you want it to open the current PWD you are in. Then you need to put a dot after it, like so ‘nautilus .’.

Great now just right click and remove that folder.

Thanks for reading.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.