Ok it’s time for a new Linux Basics Commands tutorial! Today we’re going to see some basic commands that allows you to create, move or delete files and directories in a Linux shell.
While some of you may prefer to use a GUI like Gnome, it’s always nice to learn this basic stuff. Sometimes you don’t have remote access to your desktop or the X server is crashed so you better know some shell commands.
The linux command to create a directory is mkdir. The syntax is pretty:
mkdir [directory]
So if you wanted to create a directory named “documents”, you would simply type:
mkdir documents
To verify that the directory has been created successfully, simply type ls to list all files and directories.
Now to remove a directory, the command is rmdir. The syntax is the same as mkdir, so to remove a directory named “documents”, you would type:
rmdir documents
A directory must be empty before it is removed using rmdir. So how do you remove a non-empty directory? Well you would have to use the rm command and force it’s execution. Let’s pretend we want to remove the “documents” directory which isn’t empty:
rm -f documents
In this case, the “f” switch forces the deletion of all the directory’s content. If you didn’t use the “f” switch, then you’d have to confirm the deletion of each file one by one.
The command to delete a file is rm. The syntax is:
rm [filename]
So if you wanted to delete a file named mydocument.txt, you would type:
rm mydocument.txt
If you want to delete multiple files, you could use a wildcard:
rm *.txt
This would delete all files with the .txt extension. Just as with directories, you can use the “f” switch to force deletion so you don’t have to answer yes for each file to delete:
rm -f *.txt
Moving files or directories on a Linux box is achieved using the mv command. The syntax is:
mv [source] [destination]
So let’s say you want to move the “documents” directory to the “tmp” directory (assuming it already exists), you would type:
mv documents /tmp/
This would move the documents folder into /tmp (ie.:/tmp/documents).
Now how about renaming the “documents” folder to “mydocuments” (assuming “mydocuments” does not exist!). You would use the mv command this way:
mv documents mydocuments
Pretty easy huh? The same thing would apply to a file instead of a directory.
Want more tutorials on using basic Linux commands? Subscribe to my feed by email!
| 1 | InMotion Hosting - $5.95 |
| 2 | WebHostingHub - $4.95 |
| 3 | iPage - $2.99 |
| 4 | JustHost - $3.45 |
| 5 | HostGator - $4.95 |
| 6 | FatCow - $3.67 |
| 7 | GreenGeeks - $4.95 |
| 8 | HostMonster - $5.95 |
| 9 | BlueHost - $6.95 |
| 10 | GoDaddy - $4.31 |
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment