Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

These five task-based guides show how to manage files, work with text, control processes, handle permissions, and automate or run commands remotely—while reducing the risk of changing the wrong thing. Examples assume Bash on a typical GNU/Linux system. Your shell and installed utilities may differ: Linux is the kernel, while the shell and command-line tools come from the system’s userland. The Linux command-line environment is not one identical command set on every distribution.

A terminal emulator displays a session; a shell interprets what you type and launches commands. The prompt is the shell’s display, not part of your command. A common command shape is command [options] [arguments]: in ls -lah ~/Documents, ls is the command, -lah contains options, and ~/Documents is an argument. In common shells, ~ expands to your home directory. Quote paths with spaces, such as "$HOME/Work Notes".

Practice in a disposable directory before working on important data:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mkdir -p "$HOME/terminal-lab"]/code>

Correction: use this command to create the lab directory:

mkdir -p "$HOME/terminal-lab"

Commands below are ordinary utilities unless stated otherwise. Shell built-ins such as cd, jobs, and export are handled by the shell itself; Bash’s behavior and scripting features are documented in its manual. For quick discovery, try type cd, command -v grep, grep --help, man find, info coreutils, or apropos 'disk space'. Help text is a useful start, not always a complete account of edge cases.

At a glance

Guide What you’ll do Useful commands
Files Navigate, copy, find, and measure pwd, ls, find, cp, du, df
Text Search and summarize logs or output grep, less, tail, sort, awk
Processes Inspect, background, stop, or reconnect ps, pgrep, jobs, kill, tmux
Permissions and archives Understand access and package files id, chmod, sudo, tar
Automation and remote work Repeat tasks and work over SSH Bash, ssh, scp, sftp, tmux

1. Navigate and manage files safely

Goal: Know where you are, locate the right files, and copy or move them without guessing.

Start by checking your location and listing its contents:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
pwd
ls -lah
cd /path/to/directory
cd ..
cd -

pwd prints the current working directory. ls -lah shows a long listing, includes hidden entries, and uses human-readable sizes. Hidden names begin with a dot, so ordinary ls omits them. cd .. moves up one directory; cd - returns to the previous one. The command mkdir -p project/{src,docs,tests} makes nested directories using Bash brace expansion; brace expansion is a shell feature, not a feature of mkdir.

Try a small copy workflow:

mkdir -p "$HOME/terminal-lab/source" "$HOME/terminal-lab/backup"
cd "$HOME/terminal-lab"
printf 'demon' > source/example.txt
cp -v source/example.txt backup/
find . -type f -print
du -sh .

You should see example.txt in both source and backup; cp -v reports the copy, find lists regular files below the current directory, and du -sh . reports a human-readable summary of space used by this tree.

  • cp copies; mv renames or moves. Use cp -i or mv -i when you want a prompt before overwriting an existing destination.
  • rm removes directory entries; it normally has no recycle bin. Use rm -i file.txt for an interactive prompt. Treat recursive removal as high-risk.
  • find . -type f -name '*.log' searches below the current directory for matching regular files. Quote the pattern so the shell does not expand it before find receives it.
  • stat file.txt shows detailed metadata. ls -l is useful for an overview but is not a full substitute.

Use du to investigate space used by files in a tree and df -h . to check capacity and free space on the filesystem containing the current directory. They measure different things, so their numbers need not match. For example, a deleted file can still occupy space while a process has it open.

When a result looks wrong, stop and inspect before continuing:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
pwd
ls -la
find . -maxdepth 2 -type f

For a disk check on common GNU/Linux systems, du -xhd1 /path/to/check summarizes one level of directories without crossing filesystem boundaries. -printf for find and some du options shown here are GNU-oriented, not guaranteed on BSD, macOS, BusyBox, or other minimal systems. Check man find or find --help on your system. A path beginning with a hyphen may be parsed as an option; use a path such as ./-filename or, where supported, place -- before the path. Use ls -l to spot symbolic links and find . -type l to locate them; recursive operations can behave unexpectedly when links are involved.

2. Search, inspect, and transform text

Goal: Find relevant lines in logs or files, then summarize them without dumping a large file to the screen.

A shell connects commands with pipes and redirects their output. A pipe (|) sends one command’s standard output to another command’s standard input. > creates or truncates a destination file; >> appends; 2> redirects standard error. For example:

printf 'firstn' > output.txt
printf 'secondn' >> output.txt

These redirection operators are interpreted by the shell, not by printf. Be cautious: the shell opens a file for > before running the command, so an existing file can be erased even if the command later fails. To combine standard output and error in a portable shell form, use command >output.log 2>&1; shorthand such as &> is shell-specific.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make a sample log and search it:

cat > "$HOME/terminal-lab/access.log" <<'EOF'
200 /index.html
404 /missing.css
500 /api/orders
404 /missing.css
EOF
grep -n '^404 ' "$HOME/terminal-lab/access.log"
awk '{count[$1]++} END {for (code in count) print code, count[code]}' 
  "$HOME/terminal-lab/access.log" | sort -n

The first search prints the two matching lines with their line numbers. The summary counts entries by first field; after sorting, the output is 200 1, 404 2, and 500 1. awk iterates its associative array in no guaranteed presentation order, which is why the example sorts the result.

  • grep -i ignores case; grep -n adds line numbers. Anchors such as ^ and $ match the start and end of a line.
  • Use less app.log to inspect a large file interactively, head -n 20 file for its first lines, and tail -f app.log to follow appended lines. Log rotation can replace the file being followed, so you may need to reopen it or use a rotation-aware tool.
  • sort names.txt | uniq -c counts adjacent identical lines, so sorting first groups duplicates. cut -d: -f1 /etc/passwd extracts colon-delimited fields; it is not a CSV parser.
  • awk '{print $1}' file processes fields and records, making it more than a search tool. sed -n '1,20p' file prints the first 20 lines without editing the file.

To search source files recursively, try grep -RIn --exclude-dir=.git 'TODO' .. Treat file formats as formats: whitespace splitting is not safe for arbitrary CSV, JSON, or logs with a different layout. If a search gives odd output, quote the pattern, confirm the target file is text, and inspect a few lines with less. In-place editing with sed -i changes files directly; check the expression on sample input and make a backup before using it on important files. GNU and BSD versions of tools can have different options.

3. Monitor and control running work

Goal: Identify a running command, send it a graceful stop request, or keep an interactive session available across many SSH disconnects.

For a quick view of processes, use ps aux or top. To search by name, pgrep -af process-name shows matching process IDs and command lines on common Linux systems. The exact options supported by ps vary by implementation; check ps --help or man ps.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run a harmless background job to see shell job control:

sleep 300 &
jobs -l
pgrep -af 'sleep 300'

The ampersand starts the command in the background. jobs -l lists jobs known to the current shell; its job identifier, such as %1, is not the same thing as a system process ID. ps and pgrep can locate processes outside that shell’s job table. In a real case, verify the process and its PID before sending a signal:

ps -o pid,ppid,user,stat,etime,%cpu,%mem,cmd -p PID
kill -TERM PID

TERM asks the process to exit and gives it a chance to clean up. Check again before doing anything else. Use KILL only as a last resort after confirming the PID: it forces termination and cannot be caught for cleanup. Avoid using pkill with a vague name, since it may match more than the intended process. A process started with sudo may also require appropriate privileges to inspect or manage.

For a long-running command that need not be interactive, nohup long-command > output.log 2>&1 & can help it ignore a hangup signal and send output to a file. It is not a complete process supervisor and does not guarantee that every program will keep running independently. A service manager or scheduler is a better choice for reliable production work.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For an interactive remote task, start it inside tmux:

tmux new -s maintenance

Run the task in that session. Detach with Ctrl+b, then d; later reconnect with:

tmux attach -t maintenance

tmux provides terminal sessions, windows, and panes, and lets you detach and reattach after many terminal or SSH disconnects. It does not protect against a host reboot, process crash, or storage failure. If a process appears stuck, inspect its elapsed time, state, and command line before intervening. On Linux, /proc/PID/cwd and /proc/PID/fd can provide clues about its working directory and open files, subject to permissions and system configuration.

4. Understand permissions, use administration carefully, and manage archives

Goal: Diagnose access problems and package or restore files without applying broad permission changes or extracting blindly.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start with your identity and the file’s permission bits:

id
ls -l file.txt

In a listing such as -rw-r-----, the first character identifies the file type; the next three positions are permissions for the owner, the next three for the group, and the last three for others. In numeric modes, read is 4, write is 2, and execute is 1. For example:

chmod 640 private.txt
chmod u+x deploy.sh

chmod 640 sets the selected permission bits to owner read/write, group read, and no permissions for others. chmod u+x adds execute permission for the owner. Numeric modes set permissions; they are not an instruction to add one bit. Avoid chmod 777 as a blanket fix, and do not use recursive chmod or chown without understanding every affected file.

“Permission denied” does not automatically mean you need an administrator. Check the path, owner, group, and whether the filesystem is read-only or otherwise restricted. sudo runs a permitted command under an authorized identity according to system policy; it is not a permanent permission repair. Check what you are allowed to run with sudo -l, and elevate only the specific command that requires it, for example sudo systemctl restart service. sudo’s policy and behavior depend on how the system is configured.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create and inspect an archive before extracting it:

tar -czf backup.tar.gz project/
tar -tzf backup.tar.gz
mkdir -p restore
tar -xzf backup.tar.gz -C restore

The first command creates a gzip-compressed tar archive; the listing previews its members; extraction is confined to a separate directory. For an archive you do not trust, inspect names for absolute paths or parent-directory traversal such as ../ before extracting. Extracting over existing files can overwrite them, and archive metadata or ownership may need separate consideration.

Installing an additional utility such as tree depends on your distribution and repository policy. These are examples, not interchangeable commands:

Distribution family Common package manager Example
Debian or Ubuntu apt sudo apt install tree
Fedora or RHEL-like dnf sudo dnf install tree
Arch pacman sudo pacman -S tree
Alpine apk sudo apk add tree

Check your distribution and local repository guidance first; minimal servers and containers may not include a command you expect. The GNU Coreutils manual covers many familiar file, directory, text, and permission utilities, but it is one collection—not the whole command-line environment. Its manual is a useful reference for GNU tools.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

5. Automate repeatable work and use remote shells safely

Goal: Turn a repeated file operation into a small Bash script, then run commands on a remote host without confusing local and remote paths or losing an interactive session.

Save this as copy-tree to copy a source into a destination directory:

#!/usr/bin/env bash
set -Eeuo pipefail

src="${1:?Usage: $0 SOURCE DEST}"
dest="${2:?Usage: $0 SOURCE DEST}"

mkdir -p -- "$dest"
cp -a -- "$src" "$dest"
printf 'Copied %s to %sn' "$src" "$dest"

Quote variable expansions so spaces and wildcard characters in paths remain part of the value. The -- marker tells supporting utilities that following arguments are paths, not options. The parameter checks show a usage message if either argument is missing. Test with disposable inputs before using the script on important data.

Run it with Bash explicitly, or make it executable and invoke it directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
bash ./copy-tree "$HOME/terminal-lab/source" "$HOME/terminal-lab/backup"
chmod u+x ./copy-tree
./copy-tree "$HOME/terminal-lab/source" "$HOME/terminal-lab/backup"

Do not run a Bash script with sh script if it relies on Bash syntax; sh may be a different shell. Bash supports variables, expansion, pipelines, job control, and scripts; other shells differ. Dash is commonly used for POSIX shell scripts on some systems, Zsh is popular interactively, and Fish has different scripting syntax. set -Eeuo pipefail can expose certain failures, unset variables, and pipeline errors, but it is not perfect error handling: Bash has exceptions to errexit, and scripts with important side effects may need explicit checks and cleanup traps. Avoid parsing ls; use quoted paths, globs, or carefully designed find loops instead.

For remote work, OpenSSH provides a straightforward baseline:

ssh user@server
ssh user@server 'uname -a && uptime'
scp ./local.txt user@server:/tmp/
sftp user@server

The quoted command runs on the remote host after SSH connects; quoting matters because local and remote shells can each perform expansion. Use SSH keys rather than putting passwords in scripts. Connections can fail because of DNS, routing, firewall rules, host-key checks, account permissions, or server-side SSH configuration. Do not disable host-key verification just to suppress a warning; verify the host identity through a trusted channel.

For an interactive task that should survive many connection drops, connect and start tmux new -s deploy before launching it. For unattended production services, use an appropriate service manager or scheduler rather than treating a terminal session as supervision. Remote access tools do not replace account permissions, patching, SSH security, or backups.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A short safety check before you run a command

  1. Confirm location with pwd and inspect targets with ls -la.
  2. Discover what will run: use type command for shell built-ins, aliases, or functions, and command -v command to locate an executable.
  3. Read command --help or man command before using unfamiliar options. A command copied from the web is not safe merely because it is popular; inspect downloaded scripts before executing them.
  4. Quote paths and variables; use an isolated test directory for destructive or recursive operations.
  5. Use sudo -l before elevated work and avoid a root shell when only one command needs privileges.
  6. For an interactive long-running remote task, start tmux first and remember it is not a backup or a service manager.

For more command details, see the GNU Coreutils manual index, the sed manual, and the relevant shell manual. Check the documentation installed on your own system when GNU/Linux examples behave differently on another Unix-like platform.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.