How to manage files from the command line
The handful of Linux commands that handle everyday file management jobs faster than an FTP client, once you have shell access set up.
If your hosting account offers SSH access, the command line handles a lot of everyday file management faster than opening an FTP client for the same job — particularly searching across many folders, moving or renaming a large number of files at once, and checking or changing permissions without clicking through a graphical dialogue for each one.
Not every hosting plan includes it. Look in the SSH section of your control panel, or check your welcome email — if it is available, you will find connection details there in the same place as your FTP details. If it is not available on your plan, everything in this guide has an equivalent in an FTP client or the file manager instead.
Connecting
Connect over SSH using the host, username and port shown in your control panel, the same way you would gather details for an FTP connection. Once connected, you are working directly in a shell on the server rather than through a graphical file listing.
Finding your way around
pwd # show the folder you are currently in
ls -la # list files, including hidden ones, with details
cd public_html # move into a folder
cd .. # move up one level
The -la combination on ls is worth remembering on its own: the l gives a detailed listing including permissions and file size, and the a includes hidden files — the same dotfiles that do not show by default in most graphical listings.
Searching for a file
find . -iname "*logo*"
find . -name "*.pdf" -newer .htaccess
The first command searches the current folder and everything inside it for a file with "logo" anywhere in the name, ignoring capitalisation. The second finds every PDF newer than the .htaccess file, a useful trick for finding recently added files without knowing their names.
Copying, moving and renaming
cp oldfile.html newfile.html # copy a file
cp -r old-folder new-folder # copy a folder and everything inside it
mv file.html archive/file.html # move a file into another folder
mv old-name.html new-name.html # rename a file
There is no separate rename command — moving a file to a new name in the same folder is how renaming is done. This trips up people new to the command line more often than anything else on this page.
Checking and setting permissions
ls -l file.php # see the current permission of one file
chmod 644 file.php # set a file to 644
chmod 755 folder-name # set a folder to 755
chmod -R 644 images/ # apply 644 recursively to everything inside a folder
The command line makes it just as easy to type chmod 777 as any correct value, and just as damaging. It grants full read, write and execute access to every user and process on the server. If a permission error persists after setting the correct 755 or 644 value, the permission number is very likely not the actual cause — see changing file permissions for what else to check.
Compressing and extracting
zip -r site-backup.zip public_html/
unzip archive.zip
unzip archive.zip -d target-folder/
Compressing a folder before downloading it, or extracting an archive straight on the server after uploading it, avoids transferring thousands of individual files one at a time — the same principle covered in uploading a very large file, done here from the shell instead of a file manager.
Deleting, carefully
rm file.html # delete a single file
rm -r old-folder/ # delete a folder and everything inside it
Unlike some graphical file managers, rm deletes immediately and permanently, with no confirmation step and no recycle bin to recover from. Double-check the exact path before pressing enter, especially with -r, and keep a backup of anything important before deleting in bulk this way. See deleting files without breaking your site for the habits worth applying regardless of which tool you delete with.
Why bother, if FTP already works
For a single file, an FTP client and the command line take about the same effort. The difference shows up at scale: renaming five hundred files, searching every folder on the account for one string of text, or setting permissions correctly across an entire deployment are all a single command on the shell and a great deal of manual clicking in a graphical client. If you find yourself doing the same repetitive file task often, it is usually worth the initial investment of learning the handful of commands above.
For a broader set of commands beyond file management specifically, see essential Linux commands, and for getting connected in the first place, connecting to a VPS over SSH covers the same login process this guide assumes.
Related reading
SSH is how you control a VPS from the command line, and setting it up properly the first time saves you a lot of trouble later.
How to change file permissionsSetting the right permission number on a file or folder using your FTP client or file manager, and the one number to never use.
The Linux commands you will actually useThe commands that come up constantly on a real VPS, grouped by what you are actually trying to do rather than listed alphabetically.
FTP, FTPS and SFTP: which to useThree protocols with confusingly similar names, one of which sends your password in the open. Here is what actually separates them.