New answers tagged

0 votes

Copy some files from source directory A to directory B and some files to Directory C with non sequential order

This code will copy one file to B/ and the next file to C/ and repeats until all files in A/ are copied: for f in A/*; do i=$((i+1)) o=$((i%2)) [[ "$o" -eq 0 ]] && cp -v -- "$f&...
  • 17k
3 votes

permission will not change on sd card file

The FAT32 you're using on your SD-card does not support changing unix file permissions. All files will have exactly one permissions mask, which can be set when mounting FAT32 with umask= mount option. ...
  • 3,463
0 votes
Accepted

Can't View what inside directory but can view file inside of that directory

You need to understand how directory permissions work. read(r): Allows listing the names of entries in the directory but not entry metadata or contents. write(w): Allows adding, removing, or moving ...
0 votes

Script Isn't Working at Reboot

cron jobs' environment is not your own, so use one of the mechanisms bash supplies to run your script. From the bash man page: executes /etc/profile, if that file exists. After reading that file, it ...
  • 15.9k
0 votes

How to calculate the UDP input Bitrate and Output Bitrate

install this tool sudo apt-get install lsof and use this command where 1001 is a port lsof -i :1001
  • 1
4 votes
Accepted

get the username of the user who called script with sudo

Try this: #!/usr/bin/env bash echo "$SUDO_USER"
0 votes

bash: ./mmwave_sdk_02_00_00_04-Linux-x86-Install.bin: cannot execute binary file: Exec format error

As @user10489 mentioned the mmWave SDK is provided for x86 arch (both linux and windows), so won't be able to install it on jetson, as TI don't provide full code. However, you most probably don't need ...
2 votes

Replace a line of text in a file, with the contents of another file

You can use the sed editor's r command to read the contents of a file and insert them, deleting the original matching line after: sed -e '/rule_map = /{r fix_rule_map_in_foo' -e 'd;}' foo.py The new ...
2 votes

Replace a line of text in a file, with the contents of another file

You can set that single line contained in the file fix_rule_map_in_foo in a variable named e.g. fix with command substitution like so: fix="$(cat fix_rule_map_in_foo)" You can set the ...
  • 17k
0 votes

adduser fails with error code 1 and then error code 6

you can try creating the user with no group like below: sudo adduser <username> --system the user will be created with group 'nobody'. Then if you would like to add the user you created to a ...
  • 1
2 votes

Bash Equivalency Struggles

pacmd list-sources usually results in lines with leading spaces/tabs ... That might result in the two strings you are comparing to be not equal ... Spaces count. You can use =~ for partial match e.g. ...
  • 17k
1 vote

Remove parent folder but keep subfolder intact?

Move folder2 to wanted new position and remove folder1 (which now must be empty): mv /home/radamand/folder1/folder2 /home/radamand/folder2 rmdir /home/radamand/folder1/ should do it, I think.
  • 6,235
2 votes

How to log URL to a file only if it’s HTTP status code is 200?

If you want the HTTP response/status and the URL saved to a file in the format you desire. then curl alone can do that ... It has the option -w or --write-out(Which defines what to display on stdout ...
  • 17k
0 votes

Yad Button closed

Further to my comment, I did some experimenting and came up with this script, which I believe does exactly what you want. While the documentation says that a form must call a function, with my version ...
  • 488
1 vote
Accepted

I've implemented a code that will check if the user input value is single digit or double or triple or more than that

Just missing some ['s. Try something like: #!/bin/bash read -r num if [[ "$num" -lt 10 ]]; then echo "Single" elif [[ "$num" -lt 100 ]]; then echo "Double&...
0 votes

tmp directory in $HOME with behavior like /tmp

I put a script named /etc/profile.d/tmp-user.sh which is if [ "$EUID" -ne 0 ]; then if [[ ! ( -d /home/$USER/tmp ) ]]; then if [[ ! ( -d /tmp/tmp_$USER ) ]]; then ...
0 votes

how to source csh script from bash environment?

I don't know csh but I have a similar requirement for ksh. My hack solution was to eval source <(ksh -c ". /path/to/my_script.ksh env|sort) I ran into issues with quoting and ended up putting ...
  • 1
0 votes

Copy Files to multiple folders and remove the source file

Use cp N-1 times and finally use mv for the Nth time. cp [files] [folder1] cp [files] [folder2] ... cp [files] [folderN-1] mv [files] [folderN]
0 votes

How Do I Set All KDE Look And Feel Settings In A Script?

Plasma Configuration Saver is an applet to do exactly this (with the exception of SDDM and Plymouth themes, which are system-wide settings). It can be added installed as a widget. https://store.kde....
  • 10.8k
0 votes

How do I make a custom path identifier?

You can also customize your alias just like I do alias work = "cd ~ && cd /home/anish/workspace" It's also the better approch suppose you are in some directory and you have to ...
0 votes

Can I implement tab autocomplete in a bash script?

I believe you would benefit from reading on How to create script with auto-complete? If the cd workaround doesn't cut it for you, you could try this approach an replace the static values with a ...
  • 1
8 votes

Renaming files with a year prefix from the beginning of the filename to the end

You can use rename command with regexp: rename 's/(\d+) - (.*)\.avi/$2 - $1.avi/' *.avi explained: rename - command (you may have to install it) s/<match>/<replacement>/ (substitute ...
  • 183
0 votes

How I can add to variable values in while loop using read line?

I can't think of a good reason to do this (except perhaps as a homework exercise), but yes, in bash, you can "add variables in a while loop using read". In particular, man bash notes of the +...
0 votes

How I can add to variable values in while loop using read line?

Don't try to reinvent the wheel: passWord_input="" while [[ "$passWord_input" != "$verifPassword" ]]; do read -s -r -p "Enter Password: " passWord_input ...
0 votes
Accepted

Can't Create a Permanent Alias In Fish Shell

Ok, I figured it out. Basically, in the fish shell, you just need to type alias pd="pwd" and you create a temporary alias. To turn it into a permanent one you do funcsave pd and is done. ...
0 votes
Accepted

Bash export errors when ssh-ing in

There is a space missing in front of #. Add the space manually with an editor or run, sudo sed -i 's/PATH#/PATH #/' /etc/profile
  • 25.2k
4 votes
Accepted

How can I print text while downloading file in ubuntu?

Main script: Create the following script as the source for your progress/bouncing bar (I called it bash-progress): #!/bin/bash # Initial configuration variables # Set time interval for progress ...
0 votes

How to determine whether a partition is a LUKS partition from its mountpoint?

This worked for me: for part in $(lsblk -o NAME -ln | grep -E '^[^loop]'); do if cryptsetup isLuks /dev/$part 2> /dev/null; then lsblk /dev/$part -ln -o MOUNTPOINT fi done The ...
  • 1
0 votes

Launch .desktop file from bash script and await exit

You could try the below, in a bash script: command2 is executed only if command1 returns an exit status of zero. command1 && command2
  • 132
2 votes

I have been unable to convert a script I used on Ubuntu 18.04 to my upgraded 22.04

Make the script executable A script is just a plain text file. You have to tell Ubuntu that that the file is executable. There are various way of doing it. In a Terminal The command line method is tow ...
  • 29.2k
1 vote
Accepted

Using UTF-16 syntax to include Unicode characters in Bash prompt (PS1)?

If you want to use \xHH or \uHHHH bash sequences in your pretty prompt, use a $ before first simple quote like this: PS1=$'[\\u@\\h \\W]$ \xe2\x9e\xa4 ' or PS1=$'[\\u@\\h \\W]$ \u27A4 ' Of course, ...
3 votes
Accepted

My cron doesn't find a file

As the error message clearly states, the problem is that the script can't find the file List.csv (when run with Cron), because you haven't stated the full path. Edit line 21 in your script to: file = ...
0 votes

Doing simultaneous things in a bash script?

I understand, your want to do something like that: gnome-terminal --tab -- sh -c "conda activate env_num_1 && jupyter lab" @see warning in man gnome-terminal for --command, -e=...
3 votes

Bash execution is not working with one liner, how to fix that?

Your first command, the one that works, uses curl's -L option which is (from man curl): -L, --location (HTTP) If the server reports that the requested page has moved to a ...
  • 95.5k
14 votes
Accepted

Why doesn't the wildcard "?" work?

I think it is working fine: A * will be replaced with any number of characters on the command line. A ? will be replaced by exactly one character. So for example ls dot?.txt will show dot1.txt, ...
  • 1,928
0 votes

How to exclude words using grep?

You may use the -Ev flag: grep -Ev 'house|garden' file.txt will show all lines that do not the words "house" or "garden". -E: Interpret PATTERN as an extended regular expression -...
  • 4,183
3 votes

Redo keyboard shortcut in Ubuntu shell (Bash)?

Is there a redo keyboard shortcut? Not directly in Bash, as mentioned already in another answer. However, when editing more complicated command-lines, you might want to open it in an editor that can ...
  • 9,617
1 vote

How to insert tabs before output lines from a executed command

I found an easier way: your-command | paste /dev/null - From man paste.1: Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.
2 votes
Accepted

How to store long commands in environment variables in Linux?

You should save as array and quote correctly. Only then you can be sure that it expands correctly. cmd=("docker" "ps" "-a" "--format" "table {{.Images}}\t{{...
  • 25.2k
1 vote
Accepted

Unable to view the contents of the /etc/environment file

set path variable in .bashrc nano ~/.bashrc note: user can edit this file no sudo needed go to bottom of file add line like export PATH=$PATH:/sbin CTRL-X (exit nano) save modified file -- type Y ...
  • 1,544
0 votes

Launching bash file exits after first command with "Terminated" message while it runs well within terminal

After reading the following links: https://stackoverflow.com/questions/2175647/is-it-possible-to-detect-which-trap-signal-in-bash/2183063#2183063 https://stackoverflow.com/questions/360201/how-do-i-...
  • 4,984
6 votes
Accepted

How to list all the folders that have a subfolder with a specific name inside them using CLI Bash

Using GNU find: find ~/Documents/ -type d -name images -printf '%h\n' From the -printf section of man find: %h Leading directories of file's name (all but the last ele‐ ...
3 votes

Store the output of ffprobe into a string

Seems ffprobe, writing to stderr(comment has this mentioned already) But if you want only artist, you have to use 'w' flag as well. > $ ffprobe "Adigo Alladigo.mp3" 2>&1 | grep ...
  • 97.9k
1 vote

GTK commands in a single BASH shell script, is it possible?

I know this thread is old, still those who are seeking for an answer, there is a program named gtkdialog which might be useful. Its documentation is here and examples are here.
0 votes

S3fs can't access bucket permission denied

I was getting error on opening files. I fixed it by clearing my /tmp/cache folder.
1 vote
Accepted

How to pass an input as an argument in a bash script?

Insert something like this in your script: id=$1 $1 equals to the first command line argument passed to the script, $2 to the second one, etc. Of course it would be wise to check first if the command ...
  • 7,582
0 votes

How can I run a Bash script every time is plugged an USB device?

I developped a Python script that listens for specific devices and executes an action when the device is connected, eg: pip install udev_monitor udev_monitor.py --devices 0665:5161 --filters=usb --...
0 votes
Accepted

bash - Kill a processes if it has been running for more than one hour

I modified your provided script to do what you want (quickly cooked but should do the job) ... I tried to comment as much as I thought needed, so please read the comments in the script below. #!/bin/...
  • 17k
0 votes

How to remove all files last modified one and more months before

One way to do it is: find /path -type f ! -newermt "1 month ago" -delete Other formates like "10 minutes ago" will also work.

Top 50 recent answers are included