Executing a background job

Appending an ampersand ( & ) to the command runs the job in the background.

For example, when you execute a find command that might take a lot time to execute, you can put it in the background as shown below. Following example finds all the files under root file system that changed within the last 24 hours.

find / -ctime -1 > /tmp/changed-file-list.txt &

Sending the current foreground job to the background using CTRL-Z and bg command

You can send an already running foreground job to background as explained below:

Press CTRL+Z which will suspend the current foreground job. Execute bg to make that command to execute in background. For example, if you’ve forgot to execute a job in a background, you don’t need to kill the current job and start a new background job. Instead, suspend the current job and put it in the background as shown below.

find / -ctime -1 > /tmp/changed-file-list.txt

[CTRL-Z]
[2]+  Stopped                 find / -ctime -1 > /tmp/changed-file-list.txt

bg

View all the background jobs using jobs command

You can list out the background jobs with the command jobs. Sample output of jobs command is

jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

Taking a job from the background to the foreground using fg command

You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.

fg

If you have multiple background jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command.

In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.

jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

# fg %1

Kill a specific background job using kill %

If you want to kill a specific background job use, kill %job-number. For example, to kill the job 2 use

kill %2

All the above contents are taken from this link.

Answer from Ramesh on Stack Exchange
🌐
GitHub
github.com › agkozak › zsh-z
GitHub - agkozak/zsh-z: Jump quickly to directories that you have visited "frecently." A native Zsh port of z.sh with added features. · GitHub
Zsh-z is a command-line tool that allows you to jump quickly to directories that you have visited frequently or recently -- but most often a combination of the two (a concept known as "frecency"). It works by keeping track of when you go to ...
Starred by 2.4K users
Forked by 79 users
Languages   Shell
🌐
Arch Linux Man Pages
man.archlinux.org › man › extra › z › z.1.en
z(1) — Arch manual pages
In bash, z appends a command to the PROMPT_COMMAND environment variable to maintain its database.
🌐
TurtleBytes Suite
turtlebytes.com › blog › linux-z-command-is-a-must-have-terminal-tool
Linux 'z' command is a must have terminal tool - TurtleBytes
January 12, 2026 - The Linux z command completely changes how you move around the terminal. Instead of typing long paths or relying on tab completion, z learns the directories you visit and lets you jump to them using short, partial names.
🌐
Medium
medium.com › @sybrenbolandit › z-command-a2940c206278
Z COMMAND. Working from the command line can be… | by Sybren Boland | Medium
July 27, 2021 - The technique behind this tool is quite simple. Z stores the directories you navigate too in a file. With this z stores the frequency this directory is used. After this the matching is done on the regex after the z command.
🌐
InterServer
interserver.net › home › linux and commands › unix z commands
Unix Z Commands - Interserver Tips
April 23, 2026 - Zdiff/ zcmp is used to compare file. ... A compressed file can be viewed by using the command zcat. Compression is done using the command gzip which gives the output as a compressed file with *.gz extension and .zip.
Top answer
1 of 1
3

Executing a background job

Appending an ampersand ( & ) to the command runs the job in the background.

For example, when you execute a find command that might take a lot time to execute, you can put it in the background as shown below. Following example finds all the files under root file system that changed within the last 24 hours.

find / -ctime -1 > /tmp/changed-file-list.txt &

Sending the current foreground job to the background using CTRL-Z and bg command

You can send an already running foreground job to background as explained below:

Press CTRL+Z which will suspend the current foreground job. Execute bg to make that command to execute in background. For example, if you’ve forgot to execute a job in a background, you don’t need to kill the current job and start a new background job. Instead, suspend the current job and put it in the background as shown below.

find / -ctime -1 > /tmp/changed-file-list.txt

[CTRL-Z]
[2]+  Stopped                 find / -ctime -1 > /tmp/changed-file-list.txt

bg

View all the background jobs using jobs command

You can list out the background jobs with the command jobs. Sample output of jobs command is

jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

Taking a job from the background to the foreground using fg command

You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.

fg

If you have multiple background jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command.

In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.

jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

# fg %1

Kill a specific background job using kill %

If you want to kill a specific background job use, kill %job-number. For example, to kill the job 2 use

kill %2

All the above contents are taken from this link.

🌐
Linux Command Library
linuxcommandlibrary.com › man › z
z man | Linux Command Library
z tracks your most used directories and allows you to jump to them with minimal keystrokes. It uses "frecency" - a combination of frequency and recency - to rank directories.As you navigate with cd, z learns which directories you visit most.
Top answer
1 of 2
5

1) Your code is not correct, you missed one ] bracket somewhere. Probably after [ -z "$2" block.

2) if statement executes following command(s) and then executes block of code enclosed in then .. fi or then .. else keywords if the return value of the command(s) is true (their exit code is 0)

3) [ is just an alias for the test command (try man test). This command takes several parameters and evaluates them. For example, used with -z "$something" flags would return true (0) if $something is not set or is an empty string. Try it:

if [ -z "$variable" ]; then
    echo Variable is not set or is an empty string
fi

4) || statement is an OR. Next command would be executed if the previous one returned false statement. So in the statement

if [ -z "$variable" ] || [ -z "$variable2" ]; then
    echo Variable 1 or variable 2 is not set or is an empty string
fi

command [ -z "$variable2" ] would be executed only if variable was empty. The same could be achieved with different syntax:

if [ -z "$variable" -o -z "$variable2" ]; then
    echo Variable 1 or variable 2 is not set or is an empty string
fi

which should be faster, because it requires only one instance of the test program to be run. Flag -o means OR, so you could read it as: If variable is not set/empty OR variable2 is not set/EMPTY...

5) Statement "[ ${3:-} ]" means return true if $3 (the third argument of the script) is set.

6) >&2 is a stream redirection. Every process has two outputs: standard output and error output. These are independent and could be redirected (for example) to be written to two different files. >&2 means "redirect standard output to the same location as standard error".

So to sum up: commands between then .. fi will be executed IF the script is run with $1 empty or $2 empty or $3 NOT empty That means that the script should be run with exactly two parameters. And if not, the echo message will be printed to standard error output.

2 of 2
3

-z STRING means the length of STRING is zero.

${parameter:-word} If parameter is unset or null, the expansion of word is substituted. In your case $3 is just set with a blank value, if $3 do not have any value.

&2 writes to standard-error. I mean the stdout value of the executed command is sent to stderr,

Find elsewhere
🌐
LinuxLinks
linuxlinks.com › home › z – jump around the filesystem
z - jump around the filesystem - LinuxLinks
October 14, 2023 - z is a shell script that maintains a jump-list of the directories you actually use. It tracks your most used directories, based on 'frecency'.
🌐
GitHub
github.com › rupa › z
GitHub - rupa/z: z - jump around · GitHub
OPTIONS -c restrict matches to subdirectories of the current directory -e echo the best match, don't cd -h show a brief help message -l list only -r match by rank only -t match by recent access only -x remove the current directory from the datafile EXAMPLES z foo cd to most frecent dir matching foo z foo bar cd to most frecent dir matching foo, then bar z -r foo cd to highest ranked dir matching foo z -t foo cd to most recently accessed dir matching foo z -l foo list all dirs matching foo (by frecency) NOTES Installation: Put something like this in your $HOME/.bashrc or $HOME/.zshrc: . /path/to/z.sh cd around for a while to build up the db. PROFIT!! Optionally: Set $_Z_CMD to change the command name (default z).
Starred by 17K users
Forked by 1.2K users
Languages   Shell 64.6% | Roff 35.0% | Makefile 0.4%
🌐
Linux Handbook
linuxhandbook.com › a-to-z-linux-commands
A to Z Linux Commands
October 29, 2022 - All the Linux commands that have been covered on LHB organized in alphabetical order.
🌐
IBM
ibm.com › docs › en › linux-on-z
Linux on IBM Z
You can use z/Architecture specific commands to configure and work with the Red Hat Enterprise Linux 9.2 for IBM Z device drivers and features.
🌐
oorkan
oorkan.dev › blog › linux › make-your-life-easier-with-z-script
Make Your Life Easier With Z Script | oorkan
September 26, 2020 - Licensed under the WTFPL license, Version 2 # maintains a jump-list of the directories you actually use # # INSTALL: # * put something like this in your .bashrc/.zshrc: # . /path/to/z.sh # * cd around for a while to build up the db # * PROFIT!! # * optionally: # set $_Z_CMD in .bashrc/.zshrc to change the command (default z).
🌐
Quora
quora.com › What-does-Z-mean-in-Linux
What does Z mean in Linux? - Quora
Answer: Well, there are many things you could be talking about, but since I can’t read your mind, I’m going to just pick one of my favorites. Let’s say you run the “ps” command to see what processes are running on your system, and under the STAT column you see the letter Z: [code]527 ...
🌐
Linux Hint
linuxhint.com › z-mean-in-bash
What Does -z Mean in Bash – Linux Hint
In Bash, the -z option is used to test whether a string is empty and can be used with the test command.
🌐
Lenovo
lenovo.com › home
Ctrl Z : What does ctrl z do | Lenovo US
As one of the most important shortcuts on the keyboard, mastering this command will make your life significantly easier when it comes to managing your computer or using your design software. On Linux-based operating systems such as Ubuntu, Ctrl+Z is used to suspend a process.
🌐
IBM
ibm.com › docs › en › linux-on-systems
Commands for Linux on IBM Z
You can use z/Architecture specific commands to configure and work with the Red Hat Enterprise Linux 9.2 for IBM Z device drivers and features.