aslain.dev
0%
01 Hizmetler 02 Hakkımda 03 Projeler 04 Stack 05 Blog 06 İletişim
← Tüm makaleler Tools & DevOps

Linux Commands: Command-Line Basics (CLI)

That blinking cursor you meet the first time you SSH into a server can feel intimidating, but the core Linux commands really come down to reusing a handful of patterns over and over. Whether you manage a VPS, set up a game server, or deploy a Laravel app, navigating files, copying them, fixing permissions, and controlling processes all rely on the same small set of commands. In this guide we build the daily skeleton of the command line step by step, with real, working examples.

Knowing where you are in the terminal

Everything starts with understanding your current directory. Three commands complete that picture: pwd prints which folder you are in, ls lists the contents, and cd moves you between folders.

pwd                 # prints the full path, e.g. /home/aslain
ls -la              # detailed list, including hidden files
cd /var/www         # go to an absolute path
cd ..               # move up one directory
cd ~                # return to your home directory

The first column of ls -la output (such as drwxr-xr-x) shows permissions; the leading d marks a directory, while - marks a regular file. ~ is always a shortcut to the user's home directory, absolute paths begin with /, and relative paths are interpreted from where you currently stand.

Managing files and directories

The commands to create, move, and delete content are small but powerful. The one to treat carefully is rm: there is no recycle bin, and deleted means gone.

mkdir -p project/app/src      # create nested folders in one go
touch index.php               # create an empty file or update its timestamp
cp source.txt backup.txt      # copy a file
cp -r dist/ build/            # copy a folder with its contents (-r = recursive)
mv old.txt new.txt            # rename or move
rm temp.log                   # delete a file
rm -r build/                  # delete a folder
rmdir empty_folder            # delete only an empty folder

The rm -rf combination is powerful but dangerous: a wrong path can wipe data you never meant to touch. Rehearsing the command with ls before deleting is a good habit. Note that mv handles both renaming and moving; there is no separate "rename" command.

Reading and searching file contents

Inspecting log files, finding a configuration line, or filtering output is part of the daily routine. At the heart of this sit cat, less, and grep.

cat .env                      # print the whole file to the screen
less storage/logs/laravel.log # page through a long file (q to quit)
head -n 20 access.log         # first 20 lines
tail -n 50 access.log         # last 50 lines
tail -f access.log            # watch the file live (new lines stream in)
grep "ERROR" laravel.log      # find lines containing ERROR
grep -ri "database" config/   # case-insensitive search through a folder

tail -f is worth its weight in gold when you are trying to catch a bug: you watch the logs stream in real time as you use the app. grep becomes far more powerful when combined with pipes; for example ps aux | grep php shows only the PHP processes.

Pipes, redirection, and chaining

The heart of the Linux philosophy is connecting small tools together. A pipe (|) makes one command's output the input of the next; redirection (>, >>) writes output to a file.

ls -la | grep ".php"          # show only .php files
cat access.log | wc -l        # count lines (how many requests?)
du -sh * | sort -h            # list folder sizes, sorted
echo "hello" > note.txt        # write to a file (overwrites it)
echo "second line" >> note.txt # append to the end of the file
php artisan migrate && php artisan db:seed   # run the second only if the first succeeds

The && operator runs the second command only if the first finished successfully (exit code 0); it is ideal for safely chaining deploy steps. Do not confuse > with >>: a single arrow erases the file's contents, a double arrow appends.

Managing processes and the system

When something hangs on a server, you need to see which process is running and how much it consumes. This is where the process commands come in.

ps aux                        # all running processes
ps aux | grep nginx           # only nginx processes
top                           # live resource usage (q to quit)
htop                          # a more readable version (if installed)
kill 4821                     # terminate the process with PID 4821
kill -9 4821                  # force termination (if it won't respond)
df -h                         # disk usage
free -h                       # memory (RAM) usage

When closing a process, try a plain kill first; it gives the app a chance to shut down cleanly. Only use kill -9 when it truly won't respond, because that means "pull the plug" and the process dies before it can save anything. df -h and free -h are the first places to look when asking "Why is the disk full?" or "Why is the server slow?".

Permissions and safe habits

The most common "Permission denied" errors on web servers come from permissions. chmod changes permissions, while chown changes ownership.

chmod 644 index.php           # owner reads/writes, others read
chmod 755 deploy.sh           # everyone can execute, owner can write
chmod -R 775 storage/         # apply to a folder and its contents
chown -R www-data:www-data .  # give ownership to the web user
sudo systemctl restart nginx  # restart a service with elevated rights

A few practical habits will save you trouble: confirm your location with pwd before dangerous commands, use the Tab key to auto-complete file names (it prevents typos), recall previous commands with the up arrow, and read any command's manual with man ls. Use sudo only when it is genuinely required; root rights turn every mistake into a permanent one.

Frequently Asked Questions

How do I get out of a command that's stuck in the terminal?

Ctrl + C stops a running command. To exit full-screen tools like top, less, or man, press q. To close the terminal session entirely, type exit.

What's the difference between chmod 755 and 644?

The numbers are sums of read (4), write (2), and execute (1) permissions for owner/group/others. 644 is for regular files (not executable), while 755 is for scripts and folders because they need execute/enter permission.

Can I recover a file I deleted with rm?

No, rm deletes the file directly and permanently with no recycle bin. That is why backing up important data and rehearsing the command with ls before deleting is vital.

Need help with server administration, deployment, or VPS setup? If you're stuck configuring a Linux-based system or bringing a game/web server up from scratch, get in touch with me — let's build a solid setup together.

Bu kategorideki tüm yazılar →

Devamı için