New answers tagged

1

Why is grep | sed not doing anything? It is, but you didn't wait for it. If you press q then ffmpeg will close the stream the silence_duration values will be displayed. If you want it to print the values immediately one method is to use awk instead. How to isolate the silence_duration values? If the ultimate goal is to isolate the silence_duration values use ...


1

@terdon had it right: for some reason or other, there was no .profile in my homedir. All was okay after - as suggested - cp /etc/skel/.profile ~


1

When logging in over ssh, you are running what is known as an interactive login shell, and not an interactive non-login shell which is what happens when you open a terminal once logged in. Login shells do not read ~/.bashrc and instead read ~/.profile, ~/.bash_profile and ~/.bash_login. This is why your aliases are not present. For more details on this and ...


2

It isn't supposed to respond. It is doing exactly what it should: it reads the input and assigns it to the variable fileType. However, you then have a while loop which is checking the value of a variable that never changes: while [[ "$fileType" != "EXIT" ]]; Since the value of $fileType is set only once and before the while loop, that ...


0

You seem to be catching yourself in an endless loop. If the user did not type "EXIT", then the while loop will go on forever. Any additional text you type is just being echoed to the terminal.


0

# Init n=10 DATE0="26Sep21 06:10:14" # Seconds since 01/01/1970 SECONDS=$(date +%s --date "${DATE0}") # Add seconds SECONDS=$(( SECONDS + n )) # Reformat seconds DATE1=$(date --date "@${SECONDS}" +'%d%b%y %H:%M:%S') One line: # Init n=10 DATE0="26Sep21 06:10:14" # Compute DATE1=$(date --date "@$(( $(date +%s -...


1

I am assuming the name of the program is teste, and it is located at your home folder. Remove #!/usr/bin/env bash from the first line. The first line should be [Desktop Entry] Change the Exec entry to Exec=/home/vithor/teste Change the last line to Categories=Utility Mark the .desktop file as executable with the command chmod +x /path/to/file.desktop. ...


1

If I am getting your question right then you can simply move back directories to home folder by opening your teriminal and doing this: cd ~/my_files mv * ../


0

Bash stores a command in history so you can retrieve it later. A command that is not stored in history, for example, because you preceded it with a space, or you deleted it later from the history with the history -d command, is gone from the history and cannot, by definition, be recalled. Not in bash, and not in zsh. Of course, in terminal emulators, or if ...


6

Conversion to upper case can be done in Bash using: TEXT="foobar" echo ${TEXT^^} A rotation cipher could be implemented using tr, e.g rot13: echo $TEXT | tr 'A-Za-z' 'N-ZA-Mn-za-m' # sbbone rot5 would look like this: echo $TEXT | tr 'A-Za-z' 'F-ZA-Ef-za-e' # kttgfw A partial version without tr command: #!/bin/bash TEXT="AZ" for (( i=...


0

if the script is executable then ./path/to/script/script.sh should do it


15

Use df -i to see the number of Inodes used -> IUsed field. Or limit the output like: df --output=source,target,iused Note, that numbers from find and df -i won't necessarily match: df -i also counts directories files that link to the same inode (hard links) will count only once Some special inodes that are not linked to any directory for internal use ...


13

You can use find / to list all the files. When find's output is redirected, it outputs file names containing newlines as spanning multiple lines, so you can't just count the lines. You can output something else for each file and count the characters, though: sudo find / -type f -printf 1 | wc -c Without sudo, you probably can't access all the paths, so you ...


0

Taken from here Try this: sudo rmmod nvidia_uvm sudo rmmod nvidia sudo modprobe nvidia sudo modprobe nvidia_uvm The test >>> import torch >>> torch.cuda.is_available() True


3

Building on the other answers here, some commands that parallel export but for other categories of variables are set (which works for e.g. VARIABLE=value then set | grep VARIABLE) and env Each of these three commands, when given no arguments, prints a list of variables; which variables they will print has to do with the kinds of variables the command manages....


1

After some searching, I discovered an easy way to check the validity of a user's password using su. Here's a short script demonstrating. You can save it to a file, add executable permissions, and then invoke it using ./pw_check.sh username. #!/bin/bash # This script accepts a username as a CLI argument, # requests the password for that user, and # then ...


0

A suggestion on how to design your loop instead. #!/bin/bash while read -r; do (($REPLY > 0)) \ && echo "condition passed" \ || echo "condition failed" done < <( \ find . -mindepth 1 -perm -644 -user bac0n -group bac0n -printf 1\\n -o -printf 0\\n \ )


4

echo and export are very different commands in the first place. echo will display text. In echo $JAVA_HOME, the shell will substitute $JAVA_HOME with the contents of the shell variable JAVA_HOME it it is defined. Otherwise, $JAVA_HOME will return an empty string. export provides the "export" attribute to the shell variable. export JAVA_HOME will ...


0

#!/bin/bash tag=$(awk -F, 'NR==1{print $1}' /tmp/time.txt)# output: 17:00 sub_time=$(date -d"${tag} +1:00" +'%H:%M')#output: 16:00 current_time=$(date |awk 'NR==1{print substr($5,0,5)}')#output: 05:51 # on my system the 5th field has the time while the 4th field has the year. # so I changed that in awk if [[ "$sub_time" > "$...


1

It would be safer to convert the date strings to timestamps: %s seconds since 1970-01-01 00:00:00 UTC [[ $(date +%s -d "$sub_time") -ge $(date +%s -d "$current_time") ]] Of course you could directly do this when creating the variables: sub_time=$(date -d"${tag} +1:00" +%s) current_time=$(date +%s) if [[ $subtime -ge $...


0

Firstly Cross-verify PATH in .bashrc with following commands: which virtualenv which virtualenvwrapper.sh output of: echo $VIRTUALENVWRAPPER_PYTHON and which python3 should be same which is /usr/bin/python3 Configure the path accordingly to above results export WORKON_HOME=~/.virtualenvs export MY_PROJECT=~/my_proj export VIRTUALENVWRAPPER_WORKON_CD=1 ...


3

I think you look for: xdg-user-dir DOCUMENTS See man xdg-user-dir.


11

The issue here is not really the difference between echo and export, but rather the difference between an environment variable and a simple shell variable (and also about how the /etc/environment file is normally used). In particular, although /etc/environment happens to contain lines of the form name=value that are valid as POSIX shell variable assignments, ...


0

echo is a command for printing text and variables to stdout (or redirect). export lists the current exported variables in the shell. This thread explains why you would use export much better than I can: https://stackoverflow.com/questions/7411455/what-does-export-do-in-shell-programming ... it does a great job explaining what export is fo


0

Copy and paste the following into a file test.py #!/usr/bin/env python3 # counter = 1 while counter <= 10: print("This is line", counter) counter = counter + 1 Now run the commands chmod +x test.py ./test.py > output.txt Output should be This is line 1 This is line 2 This is line 3 This is line 4 This is line 5 This is line 6 This is ...


2

You can redirect the output of your program by using the > operator. The output is then written to the given file instead of the terminal: python3 printing.py > result Note that the text is not appended, but replaces the current content of the file. If you want to append the output to the file, use the >> operator. There is also a way to get the ...


0

curl --out + TAB works for me and makes it curl --output curl --output ~/ and then TAB works for me. --output-dir seems invalid to me. Can't find it in the man page for curl: $ man curl| grep output-dir $ man curl| grep output -o, --output <file> So it seems a validity check to me: wrong option and after that no auto complete. Tested with curl ...


0

I was searching for something, and came across both this question and: https://github.com/sharkdp/hyperfine - "A command-line benchmarking tool" YMMV


1

Loop over keys: max=0 for k in "${!arr[@]}";do if (( ${arr["$k"]} > max));then max="${arr["$k"]}" max_key="$k" fi done echo "$max_key" However, there are better options to do such things than using a bash script.


0

You can either enclose $1 in single quotes, and $var in double quotes: $ rename -n 's/(bash\.bashrc)/$1'"$var"/ * rename(bash.bashrc, bash.bashrc-old_file) or $ rename -n 's/(bash\.bashrc)/$1'"$var"'/' * rename(bash.bashrc, bash.bashrc-old_file) or enclose the whole expression in double quotes, and backslash-escape $1 to prevent it from ...


2

If you need the output of a command as a new variable, put the command between $(). Like this: folderName=$(echo $files|awk -F. '{print $1} ';) To see what you're doing, add another echo command to confirm that the folder name has been correctly constructed: echo $folderName before you do the mkdir.


0

Before setting a PATH variable, you need to understand why you are setting the PATH variable. The Path variable is where the system tries to search when you issue some command in your terminal. Example: whereis ls command shows ls is there inside /bin. The ls command only works if /bin is registered in the path variable. echo $PATH gives the currently ...


1

With rev ip="1.2.3.4" echo "${ip}" | rev 4.3.2.1


2

To have your alias definitions available anytime, define them in your .bashrc file. It is a hidden file in your home directory, and is executed automatically each time you open a terminal. Open that file with your text editor. A good place to add your own aliases is where some aliases are already defined. You will find a comment line: # some more ls aliases. ...


1

I found a way to do that by doing small changes to my code. WATCHED_MOVIE_LIST=("Tenet", "Inception", "Interstellar", "Arrival", "Escape Room") mkdir "${WATCHED_MOVIE_LIST[@]}" # '*' replaced with '@' # Added double quotations to ${WATCHED_MOVIE_LIST[@]} This code can do my work. Thanks


0

In LXQt, a good place to set environment variables for programs you will launch from the menu is in the session settings; these are located in the INI-style file ~/.config/lxqt/session.conf, in the [Environment] section. You can also configure them in the GUI under Preferences -> LXQt Settings -> Session Settings, where you will find the list in the ...


1

There are a few comments worth noting. "... the gpg passphrase (which is set by a script)". I take it you didn't write the script. Please post the script. Are there any instructions to use it? passphrase="my!pass". This doesn't mean "use ! as part of the string". !pass means "read history, and get the last command starting ...


8

Scripts that are executed for a login shell (systemwide /etc/profile, any script in /etc/profile.d, your local ~/.profile and the other files you list) define the environment of your current user - since you logged in. Any non-login shell that you subsequently open, will at least inherit the environment of your login shell. That is why you (already) have ...


1

The nohup Wikipedia Page has a reference to this issue specifically: Note that nohupping backgrounded jobs is typically used to avoid terminating them when logging off from a remote SSH session. A different issue that often arises in this situation is that ssh is refusing to log off ("hangs"), since it refuses to lose any data from/to the ...


0

While the first three seem to show that Chrony is working, the last command shows that there is still a problem: $ chronyc activity 200 OK 3 sources online 0 sources offline 0 sources doing burst (return to online) 0 sources doing burst (return to offline) 0 sources with unknown address $ chronyc sources 210 Number of sources = 3 MS Name/IP address ...


1

please replace "source ./activate" with ". ./activate" see: Bourne shell builtins good luck.


2

The other answers here are pretty good. But I sould like to add that the $ is also commonly called "string" as it is often asociated with a string. Also, I have heard ! called "bang" and * called "splat". In addition, I have heard ^ called "carrot".


0

I think you need to use the commands sort and comm for this job. For example: comm -23 <(sort -u file1.txt) <(sort -u file2.txt) > file3.txt I will leave it to you to play with the suppression flags (-1,-2,-3) for the desired outcome. I have used -23 as an example. Another perhaps easier method is using awk as follows: awk 'FNR==NR{lines[$0]=1;next}...


1

There is no need to specify the directory when using the WordPress CLI. Instead you go to the directory where the core is to be copied: cd /var/www/public_html sudo -u www-data wp core download Using sudo -u www-data ensures the files are copied with the correct ownership. From there, you can begin your WordPress installation.


0

firstname=$arr | awk '{print $2}' is actually trying to set firstname to the command of what $arr is set for so it should error out with command not found. If you echo $arr as a complete command then you can grab the positional parameter as needed. firstname=$(echo $arr | awk '{print $2}') There also are other ways to get positional parameters. Feel free ...


0

pkill -9 -f jboss || true or pkill -9 -f tomcat || true


5

You're error is in this line: b=`cat /pg/$i | head -n 2 |awk '{print $8}'` head won't give you the second line, but the n first lines. So b will actually be: 30 30 and not 30 how you said. Hence the error, 30+30 30 You would need (while keeping your complicated structure): b=`cat /pg/$i | head -n 2 |awk '{print $8}' | tail -n 1` However! There is a ...


0

SLAB=76876(cat /proc/meminfo | egrep "Slab:" | awk '{print 768762;}') the shell parses that into these words SLAB="76876(cat" /proc/meminfo | egrep "Slab:" | awk '{print 768762;}') ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ .......................................^ Where the "(cat" characters are part of the value for the SLAB ...


0

New and easiest way Configure your default integrated terminal by running the Terminal: Select Default Profile command, which is also accessible via the terminal dropdown. https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles


1

The output of the following commands should convince you that you can modify your environment variables. $ grep PATH ~/.profile # set PATH so it includes user's private bin if it exists PATH=~/bin:"${PATH}" PATH="$PATH:/usr/games" $ ls -l ~/.profile -rw-r--r-- 1 sudodus sudodus 632 dec 10 2010 /home/sudodus/.profile In other words,...


Top 50 recent answers are included