Questions tagged [shell]

The shell is Unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.

Filter by
Sorted by
Tagged with
-1 votes
3 answers
75 views

How to mark things I download automatically executable?

I spend a lot of time downloading things that I am going to execute, without a doubt, after having downloaded them. Out of the 900-ish files in my download folder right now, roughly a third is stuff ...
Jean-Michaël Celerier's user avatar
0 votes
1 answer
34 views

"mv" command with asterisk character ("*") executed using "ssh"

I am inexperienced with Linux, but I am learning every day. I have this command. ssh admin@$host mv repo/environments/qa/* /repo Does this * character mean that EVERYTHING in the environments/qa ...
Chicken Sandwich No Pickles's user avatar
0 votes
1 answer
55 views

zsh: no such file or directory error even though the file exists [duplicate]

I'm getting an error while executing a binary that the binary cannot be found. I can see it using other commands. >> ls -alh ...
Igor's user avatar
  • 3
0 votes
2 answers
34 views

Copy (Rsync) only files from subirectories

I'd be really happy about some help. Lets imagine a snapshot of a directory structure: ../test1/test6/test62.txt ../test1/test6/test65.txt ../test1/test6/test67.txt ../test1/test6/test69.txt ../test1/...
Dr. Spongebob's user avatar
0 votes
3 answers
105 views

Figuring out the time until midnight, and output the result in a text file

How could I make lets say remaining time until tomorrow (midnight, also hours and minutes) and save that to a text file, like for example, "x hours and y minutes remaining until midnight" ...
Argo's user avatar
  • 3
0 votes
0 answers
62 views

Per-user cumulative CPU time across reboots

I have installed the process accounting package (acct) and recorded data. Using sa --print-seconds --user-summary | grep "$USER", I get the process account summary for my user: wjwrpoyob ...
wjwrpoyob's user avatar
  • 376
-5 votes
0 answers
60 views

I need to sort files in recursive list, but there are some difficulties [closed]

I got some problems when I was doing the task: Output the first four elements of a recursive list of file names and attributes in the lib0 directory containing the string "ra", sort the ...
Kamilla_T's user avatar
0 votes
2 answers
44 views

Replace last nonblank line with a command output

I have a .env file like PARAM1=val PARAM2=val I want to replace the last noblank line with another file content So far I have something like below: { (sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' local.env |...
gmtek's user avatar
  • 103
0 votes
0 answers
30 views

How to find out which clipboard manager my system uses?

I am not sure if the clipboard manager works as that shell interpreter in the sense we select one and only one to use in an interactive login shell (i.e., the terminal). If so, I wonder how to find ...
Rubem Pacelli's user avatar
1 vote
1 answer
25 views

How to redirect a command for a specific application

For example, the feh program can delete the currently viewed image, presumably using the rm command at some point. Let's say that instead of deleting the file, we want to run a trash script, say trash....
kleinbottle4's user avatar
1 vote
4 answers
135 views

Read nth column iteratively in two large files, cut and paste side by side to create new nth file

I have two files with around 100,000 space-separated columns in each. I want to extract each with column of the two files, write to a separate file and do command 2. Example for a file with two ...
AMS's user avatar
  • 37
1 vote
1 answer
832 views

What does mean `^(*.c|*.md)`

I am sorry if it is a potential obvious question, but I have no idea what ^() means in ls ^(*.c|*.md) On zsh, this argument expands to everything but *.c and *.md files. What is ^? What does mean ...
Rubem Pacelli's user avatar
-1 votes
2 answers
77 views

Copy file from Server A to Server B

I have requirement to copy files from Server A to Server B And then move the copied files Server A to Archive folder I have written the script, but it takes the directory name differently. Copying ...
user3792741's user avatar
0 votes
2 answers
33 views

How to extend piped command by contents of variable?

I would like to extend this line that calls /usr/bin/mplayer for recording an audio stream. The referring script record.sh could get called multiple times in parallel and I need to know in which ...
user146500's user avatar
-1 votes
0 answers
29 views

How does "." work exactly when the path directory is included and not included to execute a script file? [duplicate]

Suppose the following structure / snap bin notepadpp <--- file If pwd returns /snap/bin/ to execute the script happens the following: a: ./notepadpp the execution works b: notepadpp the ...
Manuel Jordan's user avatar
0 votes
1 answer
20 views

Buffering follow + automatic pagination of output

I have a utility that continuously outputs live logs from a program. But it can be quite hard to read the logs lines as they scroll past me in the terminal. Ideally it should scroll to one full page, ...
David S.'s user avatar
  • 101
0 votes
1 answer
86 views

Is listing files with ls dangerous as stated on gnu.org documentation?

Is listing files with ls dangerous? If I run just ls command in a directory with unknown files, can something bad happen? Can you show me examples how running ls command is dangerous as stated in this ...
mhyynmmccs's user avatar
0 votes
1 answer
47 views

How to copy a directory structure and rename a subdirectory in the destination

Given this directory structure $ lsd --tree ...
mrt181's user avatar
  • 111
1 vote
2 answers
43 views

Shell one-liner for batch renaming music albums folders according to regexp – “zsh: missing identifier after `+'”

My music library consists of folders named after the following pattern : METAGENRE - Subgenre(s) - ARTIST - Album (year) I want to switch the year and album "tags" in the folders' names for ...
sylvainsab's user avatar
-1 votes
1 answer
66 views

How does a terminal produce accurate colors?

Background I am using terminals in various settings. Often the color output of programs is not correctly rendered on the screen. The internet is full of recipes for fixing the colors for specific ...
sjdh's user avatar
  • 221
1 vote
2 answers
93 views

How do I print out the file size in a shell script?

I'm trying to record the size of the compressed build file using Fastlane in my CICD pipeline. If I try this in the command line: du -h fileName.ipa | awk '{print $1}' it works fine. However, if I ...
KDBartleby's user avatar
0 votes
1 answer
89 views

zsh ignores zshrc most of the time (but not always)

So when I open a new terminal (kitty) my ~/.zshrc is sourced perfectly fine, oh-my-zsh works, plugins are loaded as well as the p10k theme. But if I, for example, simply run zsh (or tmux) I get a ...
beccasaurus's user avatar
0 votes
0 answers
27 views

CentOS 9 Stream SSH with PuTTy - multiline commands

I've been using CentOS versions 6, 7 and 8 for a long time. Finally, I started using CentOS 9 Stream version. It doesn't matter whether GNOME desktop version or server version (black screen), I ...
aycanuAydemir's user avatar
6 votes
3 answers
459 views

Pass result of find command as another command's multiple options

I have a CLI tool that can take an option with multiple values - The syntax is like this: CLI -I path/to/file1 -I path/to/file2 ... How can I pass the result of the find command to this CLI? For ...
hongweiy's user avatar
5 votes
3 answers
338 views

zsh -z test meaning of "+x"

I am new to zsh and have been a bash user for years. In an example zsh script I see a test: if [ ! -z ${ZSH_MOTD_CUSTOM+x} ]; then In bash I would expect: if [ ! -z "$ZSH_MOTD_CUSTOM" ]; ...
Que's user avatar
  • 53
1 vote
2 answers
67 views

Is there a native linux command other than awk/sed/perl/python that can toggle pipe output on or off?

For example, suppose I define a variable: DROP= And I have a loop: # highly compatible, streaming, # line-wise parser for embedded device # no awk or external dependency while IFS= read -r line; do ...
Chris's user avatar
  • 903
0 votes
0 answers
26 views

how to rename last part of multiple file in linux [duplicate]

I want to rename to files from below format to below format . How can i rename last part ? cheatsheetold1.gz.aux cheatsheetold2.gz.log cheatsheetold3.gz.out cheatsheetold4.gz.pdf cheatsheetold5.gz....
Anu's user avatar
  • 1
0 votes
1 answer
110 views

Is standard streams just variables?

When I run command, e.g. test -l --hello check: shell save the command to variables, $0="test", $1="-l", $2="--hello" and $3="check" shell execute ...
linuxer's user avatar
  • 27
-1 votes
2 answers
94 views

Why pipe keep sudo and redirection not? [duplicate]

Pipe (|) and redirections (<, <<, >, >>) both using standard streams (stdin, stdout, stderr), but although only pipe can keep sudo privileges, why? Works: sudo echo "hello" ...
linuxer's user avatar
  • 27
1 vote
1 answer
44 views

Converting a tcsh alias into zsh

I had a tcsh alias as follows: alias cdd 'cd `dirname \!*`' I use this to change the directory to the one containing a certain file. For instance, cdd /Users/myself/Document/Folder/File.pdf would ...
leparc's user avatar
  • 13
0 votes
1 answer
38 views

How do I determine the PID of the shell running a given pts/tty?

There are many ways to obtain the PTS associated with a given process - such as using the tty command or resolving /proc/self/fd/0 (assuming it's open and not redirected) - but what about the inverse? ...
Tenders McChiken's user avatar
0 votes
3 answers
75 views

Does `return 0` equal `true` (in sourced script to shell's environment)?

I am working on a highly portable script that users shall source to their shells, forcing me to use POSIX scripting. There are many useful functions in the script, one of them is special though, as ...
Vlastimil Burián's user avatar
0 votes
1 answer
47 views

mkfs.xfs completely ignoring "|more" redirect

trying to install gentoo linux and can't format the drive with xfs because when I run mkfs.xfs /dev/sda3 it throws an error and then displays help, but the help is so big that it takes up the entire ...
Zack's user avatar
  • 1
0 votes
1 answer
67 views

Check if two IP addresses are in a range

Using bash or perl on a minimal installed Linux, I am trying to validate two IP addresses if there are in a range. I came across a bash script that works well, but the fact that it prints all the IP ...
Bruce Malaudzi's user avatar
0 votes
2 answers
128 views

commands ran from Makefile are buffered, and don't print output imediately

when I run following command in shell, I see the rsync output real-time, as the files are being transfered: rsync --out-format="%n" --info=name1,del2 -rt /foo bar | sed '\@/mmc/@d' | grcat /...
Martin Vegter's user avatar
-2 votes
3 answers
95 views

sed: -e expression #1, char 101: unterminated `s' command

can someone suggest me what is going wrong here - sed -i "s|##CONNECTION_DETAILS##|${CONNECTION_DETAILS}|g" dep.yaml. The value of CONNECTION_DETAILS is in encoded form: ...
Meenal's user avatar
  • 3
0 votes
2 answers
37 views

Getting only used memory from free command every few seconds

It was explained e.g. here: Get separate used memory info from free -m command how to cut the output of free command. But I want to do this every few seconds and log it to a file. So I tried: free -g -...
Aleksander's user avatar
0 votes
0 answers
24 views

Sending files using slack-api

curl -F file=@"/home/siva/Downloads/heap2.hprof.gz" -F channels="xxxxxxxxxxxxxxxx" -H "Authorization: Bearer xxxxxxxxxxxxx" https://slack.com/api/files.upload My file ...
Siva  E5209's user avatar
25 votes
3 answers
5k views

Is it now safe to parse the output of GNU ls?

The accepted wisdom for the past few decades has been that it is never a good idea to parse the output of ls ([1],[2]). For example, if I want to save a file's modification date along with its name ...
terdon's user avatar
  • 235k
1 vote
2 answers
143 views

How to find files created one hours before?

I have the folder, the files will comning hourly daily in here. After that, i want to copy only files, which created date one hours before to other folder. For example: Currently datetime is 9:20:00AM,...
Headshot's user avatar
  • 113
0 votes
2 answers
39 views

How do you find the path from where a cli is called from?

Let's say I'm building a CLI app. Let's say it's written in Python. For simplicity's sake, let's say this app echoes the given dir or file canonical path. The user calls myApp .. How can my app know ...
Kalec's user avatar
  • 153
0 votes
3 answers
91 views

Extract UTC time and find difference

I have a file with the following sample records for buy and sell events Buy at time=Thu Aug 03 2023 14:13:08 GMT+0200 (Central European Summer Time) Sell-at time=Thu Aug 03 2023 14:53:02 GMT+0200 (...
user3696623's user avatar
0 votes
1 answer
37 views

Why does Unix background process termination line not print right after termination?

So as an example if I run: sleep 1 & sleep 2 & sleep 3 I will immediately get the process IDs e.g. [1] ... [2] ... and then the shell freezes until the sleep 3 finishes running and then ...
borna morasai's user avatar
0 votes
1 answer
62 views

Path of ${1#*=}?

What does pluginPath="${1#*=} signify as per path in linux. It is from openfoam's parafoam from directory by the way \\wsl.localhost\Ubuntu\usr\lib\openfoam\openfoam2306\bin was trying to change ...
Aryan's user avatar
  • 1
0 votes
0 answers
31 views

Bash script or the like to erase env values that host secrets once used to initialized app in a kubernetes container

I have a flask app that runs in a kube cluster. It does all the right things by using kube secrets to set the env values required to initialize the application. There are some env values I suspect ...
Edmund's Echo's user avatar
0 votes
1 answer
54 views

What's the difference between "-dm" and "-Dm" in GNU Screen?

The GNU Screen manual says: `-d -m' Start `screen' in _detached mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts. ...
Sebastian Carlos's user avatar
0 votes
0 answers
32 views

Can't connect: No route to host -- l2ping Linux

I'm testing out l2ping via a Ubuntu VM on a MacOS machine, ran using UTM QEMU. The following command: sudo l2ping -s 5000 -f <my speaker's bluetooth MAC address> produces Can't connect: No ...
user129393192's user avatar
0 votes
1 answer
37 views

Calling vim in subprocess after running cat

I am trying to create a bash function vim_run which operates as follows: user pipes command output into vim_run user can edit output user exits vim and the contents of that buffer are now executed ...
zbs's user avatar
  • 3
0 votes
1 answer
63 views

How is this exec command supposed to work in this context?

I'm working through a textbook on UNIX system administration. Chapter 3 of "Unix Third Edition" by a Syed Mansoor. Chapter 13 has the following example of exec usage which is straightforward ...
Anthony De Vellis's user avatar
-2 votes
1 answer
63 views

"for" loop is not executing on the remote server using SSH

The below "for" loop works locally on the same server. But when triggered through "ssh" protocol on remote servers, the output is not received. Please, can anyone suggest how to ...
ShyamNarayan's user avatar

1
2 3 4 5
239