If you are new to the Linux terminal, learning a few basic commands will enable you to navigate the file system with confidence. You can enter these commands via an SSH connection; the process of connecting is described in the article on connecting to a VPS via SSH. Below, we outline the most commonly used commands.
Navigating the file system
pwd: shows which directory you are currently in.ls: lists the contents of the current directory. Thels -lacommand also displays hidden files (those beginning with a full stop) and detailed information (permissions, owner, size, date).cd mappanev: enters the specified directory.cd ..moves up one level,cd ~(or simplycd) takes you to your home directory, andcd -returns you to the previous directory.
A path can be absolute (starting from the root with a /, for example /var/www/html) or relative (relative to the current directory, for example html/wp-content).
Managing files and folders
cp forras cel: copies a file. To copy folders, use the-r(recursive) option:cp -r mappa/ cel/.mv forras cel: moves or renames a file or folder.rm fajlnev: deletes the file. To delete folders, use the-rswitch:rm -r mappa/. There is no recycle bin on Linux, and deletion cannot be undone, so always check the path before usingrm -rf.mkdir mappanev: creates a new directory. The commandmkdir -p a/b/calso creates any missing parent directories.touch fajlnev: creates an empty file or updates the modification date of an existing file.
Viewing the contents of files
cat fajlnev: displays the full contents of the file.less fajlnev: displays the file in a paginated view (search:/szöveg, exit:q).head -n 20 fajlnevandtail -n 20 fajlnev: the first and last 20 lines of the file, respectively.tail -f naplo.log: continuously displays new lines as they are written to the file; ideal for monitoring logs (to exit:Ctrl+C).nano fajlnev: a simple text editor. Our article on text editors covers the basics of nano and vim.
Search
grep 'szöveg' fajlnevprints the lines containing the text.grep -r 'szöveg' mappa/searches an entire directory. We’ll explain how to display the lines before and after the grep results in a separate article.find /var/www -name 'wp-config.php': searches for files by name.
System status
df -h: disk space usage;du -sh mappa: the size of a folder (see: checking disk usage).free -h: memory and swap usage.uptime: how long the server has been running and what its load is.top: running processes in real time.
Users and permissions
whoami: which user you are logged in as.sudo parancs: runs the command withrootprivileges.chmodandchown: changing file permissions and ownership; see: file permissions in Linux.
Help and useful tips
man parancsnev: the command’s built-in documentation (exit:q); many commands display a brief help message when the--helpswitch is used.- The
Tabkey autocompletes file and command names, so you need to type less and can avoid typing errors. - Use the up arrow to recall previous commands; the
historylists previous commands. Ctrl+Ccancels the command currently being executed.
You can try out these commands on any Linux system, including your own KVM VPS.