Terminal Takeaway πŸ₯‘

A fantastic post and a must-read or -have for any Debian admin and user.

2 Likes

That reminds me of the plethora of options to search through Debian packages. To make it swift. I will just copy the commands from the Ubuntu documentation* as the Debian handbook that I have here still talks about aptitude that I do not use personally.

Search commands

apt-cache search <search_term>

Each package has a name and a description. This command lists packages whose name or description contains <search_term>.

dpkg -l *<search_term>

This will find packages whose names contain <search_term>. Similar to apt-cache search, but also shows whether a package is installed on your system by marking it with ii (installed) and un (not installed).

apt-cache show <package_name>

This command shows the description of package <package_name> and other relevant information including version, size, dependencies and conflicts.

dpkg --print-avail <package_name>

This command is similar to β€œapt-cache show”.

dpkg -L <package_name>

This command will list files in package <package_name>.

dpkg -c foo.deb

This command lists files in the package β€œfoo.deb”. Note that foo.deb is a pathname. Use this command on .deb packages that you have manually downloaded.

dlocate <package_name>

This command determines which installed package owns <package_name>. It shows files from installed packages that match <package_name>, with the name of the package they came from. Consider this to be a β€œreverse lookup” utility.

dpkg -S <filename_search_pattern>

This command does the same as dlocate, but does not require the installation of any additional packages. It is slower than dlocate but has the advantage of being installed by default on all Debian and Ubuntu systems.

apt-file search <filename_search_pattern>

This command acts like dlocate and dpkg -S, but searches all available packages. It answers the question, β€œwhat package provides this file?”.

apt-cache pkgnames

This command provides a listing of every package in the system

  • A general note on searching: If searching generates a list that is too long, you can filter your results by piping them through the command grep. Examples:

apt-cache search <filename> | grep -w <filename>

will show only the files that contain as a whole word

dpkg -L package | grep /usr/bin

will list files located in the directory /usr/bin, useful if you’re looking for a particular executable.

For more info on the usage of apt just type:

man apt

*Reference

Edit: Now you can also use the abbreviated

apt search instead of apt-cache search

3 Likes

I am not sure where to post this as it is a comprehensive guide of all apt/apt-get commands but I will just stay within the last posts here regarding apt’s usage.

I knew that Linux Mint has a ton of extra apt commands but I did not know how much actually, interesting.

2 Likes

Well, I have given some thought to this phenomenon over the last 2 years and have a couple of other solutions – though none as elegant as the double tack to indicate the end of arguments.

Create the problem:

# create an empty file with a troubling name
> --help

1) Remove the problem file by specifying the path (absolute or relative) in front of the file:

# using an absolute path
rm /home/user/path/to/--help

or simply:

# using a relative path
rm ./--help

2) Remove the file by deleting it via its inode number. First display the inode number:

ls -ltri
39482924 -rw-rw-r-- 1 mark mark      0 Aug 28 22:04 --help

Then pass the inode number to the find command with a delete action:

find -inum 39482924 -delete

@Ulfnic, thanks for giving me something to think about for the last 2 years!

1 Like

Deleting it via inode lol, brilliant never knew you could do that.

To change console tty colors

As root

echo -en β€œ\e]P7d81521”

Bright red text

echo -en β€œ\e]e1a464”

A reddish tinted oatmeal tan background wirh bright red text.

How about a WAKE UP theme?

P000ffff

Green light is just as stimulating as blue light to reduce melatonin production and cue your circadian rhythm for the day, up to an hour.

After an hour, if you are outside or under white lights, the blue light becomes twice as effective to set your circadian rhythm. May as well have both green and blue at max brightness, with no red light.

P778cf99

A faded olive-green

Or how about a warm inviting start to the day

P0ff9921

P7ffc376

I had to increase text brightness, making it more yellow because it was quite faded matching the hue of the p0

for coffee lovers:

P0281208

P7784422

I like a nice dull purple for relaxing, but dull opensuse greens are also nice

P0321621

P7786424

I have tried a variety of combonations, another one I enjoy is a warm yellow, a little more green brightness than the orange color I posted

So have fun, and the other P numbers 1-6 are for the other colors, not just black and light grey.

setterm --background yellow

can also be a simpler yet less customizable way to do this and changing P0 - P7 values affects the color choices in setterm.

1 Like

How i’d write the maze game 4 years later.

Replace the maze with any text to turn it into a playable game updating empty_space_char, player_char, and exit_char variables if needed.

Default is spaces for empty tiles, X for the player and E for exit.

#!/usr/bin/env bash
set -o errexit

{ IFS= read -r -d '' map_data || :; } <<-'EOF'
   Movement: awsd or hjkl, Quit: q                            
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ/E\β–ˆ 
β–ˆ  β–ˆ                 β–ˆ  β–ˆ  β–ˆ     β–ˆ        β–ˆ           β–ˆ     β–ˆ 
β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ 
β–ˆ     β–ˆ     β–ˆ        β–ˆ                 β–ˆ              β–ˆ     β–ˆ 
β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ 
β–ˆ              β–ˆ     β–ˆ        β–ˆ  β–ˆ  β–ˆ           β–ˆ  β–ˆ        β–ˆ 
β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ 
β–ˆ        β–ˆ  β–ˆ  β–ˆ     β–ˆ        β–ˆ              β–ˆ  β–ˆ     β–ˆ     β–ˆ 
β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 
β–ˆ     β–ˆ  β–ˆ     β–ˆ                          β–ˆ        β–ˆ     β–ˆ  β–ˆ 
β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ 
β–ˆ  β–ˆ        β–ˆ     β–ˆ        β–ˆ  β–ˆ     β–ˆ     β–ˆ           β–ˆ     β–ˆ 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 
β–ˆ           β–ˆ  β–ˆ     β–ˆ  β–ˆ  β–ˆ  β–ˆ     β–ˆ  β–ˆ           β–ˆ  β–ˆ     β–ˆ 
β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ 
β–ˆ        β–ˆ  β–ˆ     β–ˆ     β–ˆ              β–ˆ  β–ˆ  β–ˆ  β–ˆ     β–ˆ     β–ˆ 
β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ 
β–ˆ  β–ˆ     β–ˆ  β–ˆ  β–ˆ     β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ     β–ˆ     β–ˆ        β–ˆ     β–ˆ 
β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ 
β–ˆ           β–ˆ  β–ˆ        β–ˆ     β–ˆ     β–ˆ  β–ˆ  β–ˆ  β–ˆ     β–ˆ  β–ˆ     β–ˆ 
β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ 
β–ˆ        β–ˆ              β–ˆ  β–ˆ     β–ˆ     β–ˆ        β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ 
β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆ 
β–ˆ              β–ˆ  β–ˆ        β–ˆ           β–ˆ     β–ˆ  β–ˆ  β–ˆ  β–ˆ     β–ˆ 
β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ 
β–ˆ     β–ˆ     β–ˆ  β–ˆ        β–ˆ     β–ˆ     β–ˆ                    β–ˆ  β–ˆ 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ 
β–ˆ        β–ˆ     β–ˆ     β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ           β–ˆ  β–ˆ     β–ˆ     β–ˆ 
β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 
β–ˆ     β–ˆ     β–ˆ  β–ˆ  β–ˆ     β–ˆ     β–ˆ     β–ˆ  β–ˆ  β–ˆ     β–ˆ     β–ˆ  β–ˆ  β–ˆ 
β–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ 
β–ˆ  β–ˆ  β–ˆ           β–ˆ     β–ˆ     β–ˆ  β–ˆ  β–ˆ        β–ˆ  β–ˆ  β–ˆ        β–ˆ 
β–ˆ     β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ 
β–ˆ X   β–ˆ  β–ˆ     β–ˆ     β–ˆ     β–ˆ  β–ˆ        β–ˆ  β–ˆ                 β–ˆ 
β–ˆ ^ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 
                                                              
EOF

# Characters to use for map
empty_space_char=' '
player_char='X'
exit_char='E'

# Get player Y pos by counting newlines before $player_char
y=${map_data%${player_char}*}
y=${y//[^$'\n']/}
y=${#y}

# Get player X pos by counting characters before $player_char on same line as $player_char
x=${map_data%${player_char}*}
x=${x##*$'\n'}
x=${#x}

# Print map
clear
printf '%s\n' "$map_data"

# Place map in a newline split array without the player character
readarray -t map_arr <<< "${map_data//${player_char}/ }"

# Require terminal be large enough to fit map
map_wdith=0
map_height=${#map_arr[@]}
for line in "${map_arr[@]}"; do
	(( ${#line} > map_wdith )) && map_wdith=${#line}
done
shopt -s checkwinsize; (:)
if (( map_wdith > COLUMNS || map_height > LINES )); then
	printf '%s\n' "Terminal must be ${map_wdith}x${map_height} or larger to fit map" 1>&2
	exit 1
fi

player_wins(){
		printf '\E[%d;%dH%s' 1 1 "You escaped in $(( SECONDS - time_start )) seconds"
		(( y == 0 )) && printf " using \e[0;91mrule 0\e[0m"
		printf '%s' '!           '
		exit 0
}

move_player() {
	local proposed_x=$1 proposed_y=$2 proposed_tile
	(( proposed_x >= 0 && proposed_y >= 0 )) || return 0

	# Test tile player is trying to move to
	proposed_tile=${map_arr[$proposed_y]:proposed_x:1}
	[[ $proposed_tile == "$exit_char" ]] && player_wins
	[[ $proposed_tile == "$empty_space_char" ]] || return 0

	# Overwrite player location with a space and write player in new location
	printf '\E[%d;%dH%s' "$(( y + 1 ))" "$(( x + 1 ))" "$empty_space_char"
	x=$proposed_x
	y=$proposed_y
	printf '\E[%d;%dH%s' "$(( y + 1 ))" "$(( x + 1 ))" "$player_char"
	return 0
}

# Begin read input loop
time_start=$SECONDS
while read -s -n 1; do
	case $REPLY in
		w|k) move_player "$x" "$(( y - 1 ))" ;; # up
		s|j) move_player "$x" "$(( y + 1 ))" ;; # down
		a|h) move_player "$(( x - 1 ))" "$y" ;; # left
		d|l) move_player "$(( x + 1 ))" "$y" ;; # right
		q) exit 0
	esac
done

Tool used to produce map: Maze Generator (Perfect) - Online Text ASCII Labyrinth

Had no idea Bash could do something so advanced. I knew it could handle a loop (with variables), but structured programming?

I never stopped learning BASH and it never stopped showing me new things.

It’s a remarkably powerful language.

2 Likes