Basic Linux Commands
This guide introduces common Linux commands through a small practice workspace. You will navigate directories, create and search files, inspect the system, run a shell script, and create an archive.
Run the main exercise in order from a command-line shell on your device. If you need help opening a shell, select your board from the Platforms menu and follow the corresponding Access the Device guide.
Open a Shell
Open a command-line shell using the access method for your board. If you use ADB, run the following command on your development computer:
adb shell
After the device shell opens, identify the current user, device, and working directory:
whoami
hostname
pwd
For example, a board connected through ADB displayed:
root
grinn-astra-1680-sbc
/
User names, host names, and starting directories can differ. The hostname
output helps confirm that commands are running on the target device rather than
your development computer. Unless a step says otherwise, run the remaining
commands in the device shell.
Before You Start
The exercise uses mktemp to create a unique temporary directory. Temporary
files may be cleared when the device restarts. Store work that must persist
under your home directory, represented by $HOME or ~.
Run the exercise in order from the same shell. The tutorial_root variable
identifies the unique directory created for this session. Do not change that
variable or reuse it for other files.
Commands and available options can differ between Linux images. Use
command -v COMMAND to check whether a command is installed and
COMMAND --help to see its supported options.
Quick Reference
The commands below cover common file, directory, and system checks you may need while working from a Linux shell.
| Task | Command |
|---|---|
| Show command help | COMMAND --help |
| Check command availability | command -v COMMAND |
| Create a temporary directory | mktemp -d |
| Show the current directory | pwd |
| Change directory | cd PATH |
| Create a directory | mkdir -p PATH |
| List directory contents | ls -la PATH |
| Create an empty file | touch FILE |
| Read a file | cat FILE |
| Copy a file | cp SOURCE DESTINATION |
| Rename or move a file | mv SOURCE DESTINATION |
| Search file contents | grep -n PATTERN FILE |
| Find a file | find PATH -type f -name PATTERN -print |
| Make a script executable | chmod +x SCRIPT |
| Show kernel information | uname -a |
| Show root filesystem space | df -h / |
| Show running processes | ps |
| Create a compressed archive | tar -czf ARCHIVE.tar.gz DIRECTORY |
| List a compressed archive | tar -tzf ARCHIVE.tar.gz |
| Remove a directory | rm -r PATH |
| Leave the current shell | exit |
Understand Paths and Shell Operators
Linux uses / to separate directories in a path. These common path forms
appear throughout the guide:
| Notation | Meaning |
|---|---|
/ | The filesystem root |
. | The current directory |
.. | The current directory's parent |
~ | The current user's home directory |
/tmp/a | An absolute path starting at the root |
a/b | A relative path starting at the current path |
The shell also interprets operators that connect commands and files:
>writes command output to a file, replacing that file if it exists.>>appends command output to the end of a file.|sends the output of the command on its left to the command on its right.*matches text in file-name patterns. Quote patterns such as'*notes*'when they should be interpreted by a command instead of the shell.
Press Ctrl+C to stop most commands running in the foreground. Interactive programs may provide their own exit key.
Get Command Help
Ask ls, which lists directory contents, for a summary of its options:
ls --help
Work with Files and Directories
Create a unique temporary root and store its path in tutorial_root. Command
substitution, written as $(COMMAND), replaces itself with the command's
output. Create the tutorial directory beneath that root, enter it, and confirm
its absolute path. Quotes preserve the path as one argument, mkdir creates
the directory, cd changes the current directory, and pwd prints that
directory. If mktemp fails, || exit 1 leaves the device shell instead of
continuing without a safe temporary path.
tutorial_root=$(mktemp -d) || exit 1
mkdir "$tutorial_root/grinn-linux-tutorial"
cd "$tutorial_root/grinn-linux-tutorial"
pwd
The generated portion of the path differs each time. Example output:
/tmp/tmp.A1b2C3/grinn-linux-tutorial
Create an empty file with touch. Then write its first line with > and
append a second line with >>:
touch notes.txt
printf '%s\n' 'Linux command practice' > notes.txt
printf '%s\n' 'Created on the target device' >> notes.txt
cat notes.txt
Expected output:
Linux command practice
Created on the target device
Make a subdirectory, copy the file into it, rename the copy, and return to the tutorial directory:
mkdir -p copies
cp notes.txt copies/notes-copy.txt
cd copies
mv notes-copy.txt renamed-notes.txt
pwd
cd ..
Create a hidden file and directory. Names that start with . are hidden from a
plain ls listing. Use ls -la to include hidden entries and file details:
touch .hidden-file
mkdir -p .hidden-directory
ls -la
Expected entries include ., .., .hidden-directory, .hidden-file,
copies, and notes.txt. For example, a board connected through ADB displayed
the following output. Permissions, sizes, and timestamps can differ:
drwxrwxrwx 4 root root 120 Jan 8 23:59 .
drwxrwxrwt 8 root root 200 Jan 8 23:59 ..
drwxrwxrwx 2 root root 40 Jan 8 23:59 .hidden-directory
-rw-rw-rw- 1 root root 0 Jan 8 23:59 .hidden-file
drwxrwxrwx 2 root root 60 Jan 8 23:59 copies
-rw-rw-rw- 1 root root 52 Jan 8 23:59 notes.txt
The . and .. entries represent the current and parent directories.
Read and Search Files
head and tail read lines from the beginning and end of a file:
head -n 1 notes.txt
tail -n 1 notes.txt
Expected output:
Linux command practice
Created on the target device
Use grep to print matching lines. The -n option includes line numbers:
grep -n 'target' notes.txt
Expected output:
2:Created on the target device
Use find within the bounded tutorial directory to locate file names that
contain notes. The pipe sends the results to sort, making their display
order predictable.
find "$tutorial_root/grinn-linux-tutorial" -type f -name '*notes*' -print | sort
Example output, using the temporary path shown earlier:
/tmp/tmp.A1b2C3/grinn-linux-tutorial/copies/renamed-notes.txt
/tmp/tmp.A1b2C3/grinn-linux-tutorial/notes.txt
Inspect the Linux System
These commands identify the current user and device. Exact output depends on the image and hardware.
whoami
hostname
uname -a
date
uptime
df -h /
ps
whoamiprints the current user.hostnameprints the device name.uname -aprints kernel and architecture information.dateprints the system date and time.uptimeshows how long the system has been running.df -h /summarizes space on the root filesystem.psshows a snapshot of running processes.
/etc/os-release identifies the installed Linux distribution and version.
Print it with:
cat /etc/os-release
For example, a board running the Poky-based Yocto image displayed:
ID=poky
NAME="Poky (Yocto Project Reference Distro)"
VERSION="5.0.9 (scarthgap)"
VERSION_ID=5.0.9
VERSION_CODENAME="scarthgap"
PRETTY_NAME="Poky (Yocto Project Reference Distro) 5.0.9 (scarthgap)"
CPE_NAME="cpe:/o:openembedded:poky:5.0.9"
PRETTY_NAME is the human-readable distribution name and version. Some images
provide additional fields.
Create and Run a Shell Script
This optional exercise combines several commands into a repeatable report.
The cat <<'EOF' construct writes all following lines through the final EOF
marker into device-info.sh. The first line selects the standard system shell
as the script interpreter.
cat > device-info.sh <<'EOF'
#!/bin/sh
printf 'User: %s\n' "$(whoami)"
printf 'Host: %s\n' "$(hostname)"
printf 'Kernel: %s\n' "$(uname -sr)"
printf '%s\n' 'Uptime:'
uptime
printf '%s\n' 'Root filesystem space:'
df -h /
EOF
chmod +x grants execute permission. Run the script with ./, which refers to
the copy in the current directory:
chmod +x device-info.sh
./device-info.sh
An example output from a board connected through ADB is shown below. Kernel versions, uptime, storage use, and process load vary:
User: root
Host: grinn-astra-1680-sbc
Kernel: Linux 6.12.62
Uptime:
00:00:27 up 44 min, load average: 0.28, 0.11, 0.02
Root filesystem space:
Filesystem Size Used Available Use% Mounted on
/dev/mmcblk0p10 4.6G 1.6G 2.7G 37% /
Save the report for the archive exercise:
./device-info.sh > device-info.txt
Archive the Practice Files
Return to the unique temporary root, create a gzip-compressed archive, and list
its contents. The -c option creates an archive, -z enables gzip
compression, and -f selects the archive file.
cd "$tutorial_root"
tar -czf grinn-linux-tutorial.tar.gz grinn-linux-tutorial
tar -tzf grinn-linux-tutorial.tar.gz
Extract a copy into a separate directory and inspect its files:
mkdir grinn-linux-tutorial-extracted
tar -xzf grinn-linux-tutorial.tar.gz -C grinn-linux-tutorial-extracted
find grinn-linux-tutorial-extracted -type f -print | sort
Unlike mkdir -p, mkdir reports an error if that extraction directory
already exists instead of silently reusing it.
Clean Up
Inspect the uniquely created tutorial root before removing it:
printf '%s\n' "$tutorial_root"
ls -la "$tutorial_root"
rm permanently removes files instead of moving them to a recycle bin. Confirm
that tutorial_root still contains the path created by mktemp before running
the following commands.
Remove the temporary tutorial directory and all files created inside it:
cd /
rm -r "$tutorial_root"
When you finish, leave the device shell and return to your development computer:
exit