Linux Basics: Creating, Moving, Renaming and Deleting Files & DirectoriesMay 22nd, 2008 · No CommentsOk 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. Creating And Removing Directories On LinuxThe linux command to create a directory is mkdir. The syntax is pretty:
So if you wanted to create a directory named “documents”, you would simply type:
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:
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:
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. Deleting FilesThe command to delete a file is rm. The syntax is:
So if you wanted to delete a file named mydocument.txt, you would type:
If you want to delete multiple files, you could use a wildcard:
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:
Moving and Renaming Files and DirectoriesMoving files or directories on a Linux box is achieved using the mv command. The syntax is:
So let’s say you want to move the “documents” directory to the “tmp” directory (assuming it already exists), you would type:
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:
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! Related Posts |
Popular PostsLatest PostsLatest Deals & CouponsRecent Comments
Hosting ReviewsRecent WebmastersTag Cloud
1and1
apache
bluehost
centos
cheap web hosting
control panel
coupon
coupon code
cpanel
dedicated servers
dreamhost
godaddy
green web hosting
hostdime
hostgator
hostpapa
iis
inmotion hosting
knownhost
linux
lunarpages
mysql
openx
php
reseller hosting
shared hosting
system administration
vps
web hosting
web hosting comparison
Web Hosting Comparisons
whm
windows
windows 2008
wordpress
|
|||||||||
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment