Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

-2 votes
2 answers
50 views
HISTTIMEFORMAT not working as desired in RHEL 8 bash 4.4.20
so trying to capture history with date and readable timestamps AND the command should appear on same line. following is failing: Bash ver is: GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-gnu) OS: RHEL 8.x in .bashrc.... setopt EXTENDED_HISTORY export HISTTIMEFORMAT='%F %I:%M:%S %T' #expo...
so trying to capture history with date and readable timestamps AND the command should appear on same line. following is failing: Bash ver is: GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-gnu) OS: RHEL 8.x in .bashrc.... setopt EXTENDED_HISTORY export HISTTIMEFORMAT='%F %I:%M:%S %T' #export HISTTIMEFORMAT="%F %T " export HISTSIZE=1000 export HISTFILE=$HOME/.bash_history-$USER export HISTFILESIZE=1000 export PROMPT_COMMAND='history -a' env variables: $ env|grep HIST HISTCONTROL=ignoredups HISTTIMEFORMAT=%F %I:%M:%S %T HISTFILE=/home/user1/.bash_history-user1 HISTSIZE=1000 HISTFILESIZE=1000 the records appear as: #1753745611 cd #1753745616 ls -ltra|tail #1753745626 cat .profile #1753745633 cat .kshrc **expected:** Mon Jul 28 23:33:31 GMT 2025 cd Mon Jul 28 23:33:36 GMT 2025 ls -ltra|tail Mon Jul 28 23:33:46 GMT 2025 cat .profile Mon Jul 28 23:33:53 GMT 2025 cat .kshrc two problems with this. 1. Timestamp appears in UNIX EPOCH format. 2. Timestamp and command appears on separate lines. They should be together. Also behaves the same way when using KSH. How can this be fixed? preferably using HISTTIMEFORMAT Thank you.
Rajeev (256 rep)
Jul 29, 2025, 03:33 PM • Last activity: Jul 29, 2025, 10:01 PM
91 votes
16 answers
117412 views
How to color diff output?
I wanted to format the Unix files conditionally, I am currently working on `diff` command and wanted to know if it is possible to format the text of the `diff` command output. Example: >Matched values should be displayed in green. Unmatched values should be displayed in red. Suppose I have two files...
I wanted to format the Unix files conditionally, I am currently working on diff command and wanted to know if it is possible to format the text of the diff command output. Example: >Matched values should be displayed in green. Unmatched values should be displayed in red. Suppose I have two files file1 and file2 and my command is diff file1 file2 . Now I wanted that suppose output contain 5 mismatch then those mismatch should be displayed in Red color. How to achieve this using unix? In short "Change color to red for the output of diff command for values which mismatch"
Aman (1281 rep)
Apr 16, 2015, 10:11 AM • Last activity: Jul 25, 2025, 03:26 PM
2 votes
1 answers
631 views
1-liner process substitution for ksh
I have this command, which works fine for `bash`: `sh <(curl -sSl https://appi.sh/launch)` (launches [this interactive script](https://github.com/Appish/appi.sh/blob/master/launch.sh)) I'd like to get this 1-liner working for `ksh`, too. Currently, it errors with: ``` syntax error: `(' unexpected` `...
I have this command, which works fine for bash: sh <(curl -sSl https://appi.sh/launch) (launches [this interactive script](https://github.com/Appish/appi.sh/blob/master/launch.sh)) I'd like to get this 1-liner working for ksh, too. Currently, it errors with:
syntax error: (' unexpected
Running the script from ksh as sh launch.sh works fine, so I'm hoping there's a way to have a singular 1-liner that will work in both bash/ksh without exponentially increasing the length of the command.
ljs.dev (2147 rep)
Jun 17, 2020, 05:58 PM • Last activity: Jul 22, 2025, 05:09 PM
0 votes
0 answers
51 views
When i trying to execute shell script , it does out come out. keep on running
File name: `/u02/app/scmdw/scr/appcheck1.sql` Shell script: `test.ksh` #!/bin/ksh line=`sqlplus $SCMDWSA @/u02/app/scmdw/scr/appcheck.sql` echo "== Result of SQL: line = $line" When I try to execute the shell script `test.ksh`, the following step: ``` sqlplus $SCMDWSA @/u02/app/scmdw/scr/appcheck.sq...
File name: /u02/app/scmdw/scr/appcheck1.sql Shell script: test.ksh #!/bin/ksh line=sqlplus $SCMDWSA @/u02/app/scmdw/scr/appcheck.sql echo "== Result of SQL: line = $line" When I try to execute the shell script test.ksh, the following step:
sqlplus $SCMDWSA @/u02/app/scmdw/scr/appcheck.sql
The script keeps running and does not exit. I want to check how it works if I change the filename from appcheck.sql to appcheck1.sql in the directory path. I also want to capture the error if an invalid file is kept in the actual directory path. Could you please help me understand how to capture the error and why is it running for such a long time?
Celestica - Prabhahar Palanive (19 rep)
Oct 14, 2024, 05:53 AM • Last activity: Jun 24, 2025, 11:59 AM
1 votes
2 answers
650 views
ksh: appending date-time in history
Does anyone have a solution to append date and time to this as another column? It seems like it would be very useful with sorting, etc... $ history 3 history Thank you!
Does anyone have a solution to append date and time to this as another column? It seems like it would be very useful with sorting, etc... $ history 3 history Thank you!
Nick (205 rep)
Oct 30, 2019, 07:22 PM • Last activity: May 12, 2025, 09:35 AM
48 votes
1 answers
13455 views
What's wrong with var=$(</dev/stdin) to read stdin into a variable?
We've seen a few posts here lately that use this: ``` var=$(</dev/stdin) ``` in an attempt to read the shell's standard input into a variable. That is however not the correct way to do it on Linux-based systems and Cygwin at least. Why? What are the correct ways?
We've seen a few posts here lately that use this:
var=$(
in an attempt to read the shell's standard input into a variable. That is however not the correct way to do it on Linux-based systems and Cygwin at least. Why? What are the correct ways?
St&#233;phane Chazelas (579252 rep)
Sep 7, 2022, 08:22 AM • Last activity: Apr 11, 2025, 10:19 AM
8 votes
1 answers
273 views
bash or ksh 'vi' mode - How to jump to end of history (most recent command)?
I am a long time ksh user, and use bash under duress - both in 'vi' editing mode. One thing that has always niggled - after searching back through history for a command (.e.g ` /needle`), how do I then jump forward through the history again to the most recent command? `G` would be the logical 'vi' c...
I am a long time ksh user, and use bash under duress - both in 'vi' editing mode. One thing that has always niggled - after searching back through history for a command (.e.g /needle), how do I then jump forward through the history again to the most recent command? G would be the logical 'vi' command (i.e. jump to end of file)... but for some reason that jumps to the beginning of the history, i.e. the oldest command. Seeing that, you'd think the opposite might be correct, i.e. 1G, but it seems G commands are not accepted. Does anyone know the trick?
Annihilannic (318 rep)
Mar 21, 2025, 06:31 AM • Last activity: Mar 21, 2025, 07:08 AM
-1 votes
1 answers
70 views
"history -0" works in ksh, why doesn't "history -0" work in zsh?
Why does `ksh` `history -0` (last command which is the history command itself) work, yet `zsh` it fails (only `history -1` avail on my zsh). I tried `zsh -f` to use default options and it still fails. I'm using ksh version `Version AJM 93u+ 2012-08-01` and Zsh v5.9 on MacOS. This question is about t...
Why does ksh history -0 (last command which is the history command itself) work, yet zsh it fails (only history -1 avail on my zsh). I tried zsh -f to use default options and it still fails. I'm using ksh version Version AJM 93u+ 2012-08-01 and Zsh v5.9 on MacOS. This question is about the history command and not preexec() to get the current command.
atod (155 rep)
Jan 31, 2025, 04:51 AM • Last activity: Mar 10, 2025, 07:33 AM
0 votes
1 answers
57 views
ksh: how to capture the current invoked command and arguments?
How do I obtain a variable with the current command and arguments? I would like to use escape code to print this in an Xterm title bar. I see Terminal.app on MacOS is determining the name of the invoked command somehow. I see the follow implementation for zsh, however I'm looking for ksh. if [ "$SHE...
How do I obtain a variable with the current command and arguments? I would like to use escape code to print this in an Xterm title bar. I see Terminal.app on MacOS is determining the name of the invoked command somehow. I see the follow implementation for zsh, however I'm looking for ksh. if [ "$SHELL" = '/usr/bin/zsh' ] then case $TERM in rxvt|*term) precmd() { print -Pn "\e]0;%m:%~\a" } preexec () { print -Pn "\e]0;$1\a" } ;; esac fi I'm reading this post on using ksh's DEBUG trap or poster also comments that "running a background task that regularly inspects the output of ps -o stat= -o args= to see which processes run in foreground and what command they are executing" is preferred. Does anyone have more information on this?
atod (155 rep)
Jan 30, 2025, 08:31 PM • Last activity: Jan 31, 2025, 08:34 AM
3 votes
1 answers
216 views
zsh: History is skipping commands and integers+, how to correct this?
Does anyone know what's occurring with zsh below and how to get the same behavior I show with `ksh` and `bash`? I'm noticing `zsh` on MacOS v13.7 is skipping even commands numbers in its history output, while `ksh` and `bash` behave as expected. `zsh` history count is also wrong, it is 6 vs 7 comman...
Does anyone know what's occurring with zsh below and how to get the same behavior I show with ksh and bash? I'm noticing zsh on MacOS v13.7 is skipping even commands numbers in its history output, while ksh and bash behave as expected. zsh history count is also wrong, it is 6 vs 7 commands. zsh session: $ history 1 history $ ls ... $ history 2 ls $ ls df ls: df: No such file or directory $ history 2 ls 4 ls df $ ls / $ history 2 ls 4 ls df 6 ls / ksh and bash session: $ ksh $ history 1 history $ ls $ history 1 history 2 ls 3 history $ ls df $ history 1 history 2 ls 3 history 4 ls df 5 history $ ls / $ history 1 history 2 ls 3 history 4 ls df 5 history 6 ls / 7 history CONFIGARTION FILES: Keep .common-hist (relavant): export HISTFILE="${HOME}/.${HDIRPRE}-history.d/history-"uname -n"-"id -nu"-"tty|cut -c6-"" .zshrc (relavant): HDIRPRE="zsh" precmd() { setprompt } .kshrc (relavant): HDIRPRE="ksh" function prompt_cd { command 'cd' "$@" && setprompt } alias cd="prompt_cd" .bashrc: HDIRPRE="bash" PROMPT_COMMAND=setprompt I call the function setprompt to configure an xterm or Apple Terminal title bar and prompt by setting ${PS1}. I'm not sure if that's the 'extra' command missing from zsh history. Perhaps it's MacOS related.
atod (155 rep)
Jan 30, 2025, 05:23 AM • Last activity: Jan 30, 2025, 08:00 AM
0 votes
0 answers
29 views
Shell: redirecting output to /dev/tty and another file in a script? Not having to retype ending?
How do I accomplish this command to redirect command output to multiple files, without retyping the later A=`1>&/dev/tty 1>&${TMP}/lastcmdout` every time? I want to see output on the current TTY and redirect to files. The following accomplishes what I want, but I don't want to retype the ending. $ c...
How do I accomplish this command to redirect command output to multiple files, without retyping the later A=1>&/dev/tty 1>&${TMP}/lastcmdout every time? I want to see output on the current TTY and redirect to files. The following accomplishes what I want, but I don't want to retype the ending. $ cmd0 | cmd1 1>&/dev/tty 1>&${TMP}/lastcmdout I tried making a script shttf: ${SHELL} -c ${1} 1>&/dev/tty 1>&${TMP}/lastcmdout and invoking $ shttf 'cmd1 | cmd2' so I can see the output and also redirect it a file, however this isn't working. I'm considering these shells: ksh88, ksh93, zsh.
Nick (205 rep)
Jan 25, 2025, 08:15 PM
-5 votes
1 answers
65 views
how to check if a large script is only using full paths for the used cmd inside it?
to make a script more secure, we would need to confirm that used cmds, eg.: "/usr/bin/chown" instead of just "chown".
to make a script more secure, we would need to confirm that used cmds, eg.: "/usr/bin/chown" instead of just "chown".
robert8819 (21 rep)
Jan 21, 2025, 02:18 PM • Last activity: Jan 24, 2025, 09:38 PM
0 votes
0 answers
33 views
Can't use combination of parentheses and variables in scripts
I have problems with replacing parentheses in combination with variables, in ssh. For instance, replacing `(hello123blablabla)` with `(hello)`. So, it replaces all together, and parentheses as well, at least that's what I expect. But the variable value is lost when using the parentheses: ```shell $...
I have problems with replacing parentheses in combination with variables, in ssh. For instance, replacing (hello123blablabla) with (hello). So, it replaces all together, and parentheses as well, at least that's what I expect. But the variable value is lost when using the parentheses:
$ hellovar=hello
$ perl -pi.bak -e 's/\(hello[1..3].*?\)/($hellovar)/g' file.txt
The command is printed as following
$ echo perl -pi.bak -e 's/\(hello[1..3].*?\)/($hellovar)/g' file.txt
perl -pi.bak -e s/\(hello[1..3].*?\)/($hellovar)/g file.txt
But I need it to be translated as follows:
perl -pi.bak -e s/\(hello[1..3].*?\)/(hello)/g file.txt
armagedescu (101 rep)
Jan 22, 2025, 03:00 PM • Last activity: Jan 22, 2025, 03:55 PM
1 votes
1 answers
26 views
Running a command before running user input in ksh
I'm running Korn 93u+ and I want to echo the current time each time I enter a command. I currently just put the time in my PS1, but that's obviously flawed because if I leave the command line for some period of time I end up with a stale timestamp. I'd rather have an operation that executes _after_...
I'm running Korn 93u+ and I want to echo the current time each time I enter a command. I currently just put the time in my PS1, but that's obviously flawed because if I leave the command line for some period of time I end up with a stale timestamp. I'd rather have an operation that executes _after_ I hit enter, e.g.
$ ls -a1
Running at 2025-01-08 14:25:30.

.
..
dummy_dir_1
dummy_dir_2
$
Is there a way to do that config-wise?
Yehuda (331 rep)
Jan 8, 2025, 08:37 PM • Last activity: Jan 9, 2025, 12:08 AM
1 votes
2 answers
3558 views
How to change terminal title without changing the prompt string?
I have customized my command prompt to display current directory with some color and full path. Now I want to set title of my window to only directory name (not full path). Can you please advise how to achieve that in korn shell. Thanks.
I have customized my command prompt to display current directory with some color and full path. Now I want to set title of my window to only directory name (not full path). Can you please advise how to achieve that in korn shell. Thanks.
Forever Learner (769 rep)
Jan 5, 2017, 07:55 AM • Last activity: Jan 5, 2025, 04:43 PM
0 votes
1 answers
45 views
xutils.sh in open sourced CDE?
I am reading a book about dtksh. The first "hello world" example begins as follows: ``` #!/usr/local/dt/bin/dtksh . $UTILDIR/xutil.sh XUinitialize TOPLEVEL Hello "$@" XUlabel LABEL $TOPLEVEL labelString:"hello, world" XUrelize $TOPLEVEL XUmainloop ``` Is the file `xutil.sh` available in current open...
I am reading a book about dtksh. The first "hello world" example begins as follows:
#!/usr/local/dt/bin/dtksh

. $UTILDIR/xutil.sh

XUinitialize TOPLEVEL Hello "$@"
XUlabel LABEL $TOPLEVEL labelString:"hello, world"
XUrelize $TOPLEVEL
XUmainloop
Is the file xutil.sh available in current open sourced CDE in FreeBSD? I can not locate it.
M.E. (631 rep)
Jan 1, 2025, 01:26 AM • Last activity: Jan 1, 2025, 10:00 AM
5 votes
1 answers
321 views
How to determine what is opening tmp files when I invoke a subshell with ksh
I'm experiencing extremely sluggishness in opening subshells (by using \` \` or $( ) command substitutions in scripts) while in `ksh` on some Linux servers. The same problem does not exist in `sh` or any other shell. `strace` indicates that the time is due to `stat` and `openat` calls against random...
I'm experiencing extremely sluggishness in opening subshells (by using \ \ or $( ) command substitutions in scripts) while in ksh on some Linux servers. The same problem does not exist in sh or any other shell. strace indicates that the time is due to stat and openat calls against randomly named files in /tmp. **test.sh**: echo expr 1 + 1 **command**: strace -tttT ksh test.sh **output**: . . .[snipped]. . . 1734368858.571604 stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=708608, ...}) = 0 1734368859.184765 geteuid() = 1001 1734368859.184851 getegid() = 1002 1734368859.184879 getuid() = 1001 1734368859.184913 getgid() = 1002 1734368859.184946 access("/tmp", W_OK|X_OK) = 0 1734368859.185012 getpid() = 210594 1734368859.185055 openat(AT_FDCWD, "/tmp/sf0p.si0", O_RDWR|O_CREAT|O_EXCL, 0666) = 1 1734368860.771539 unlink("/tmp/sf0p.si0") = 0 . . . Between stat and openat, my simple invocation of expr 1 + 1 **took more than 2 seconds of time.** Questions: 1. Why is ksh creating files in /tmp, whereas none of the other shells (sh, bash, csh) do that? 2. How do I start diagnosing why these operations would take 1-2 seconds? Server in question is at version: Linux 5.4.17-2136.322.6.4.el8uek.x86_64 (distribution Oracle Linux Server release 8.9). Ksh is version AJM 93u+ 2012-08-01 **Update:** We've seen some artifacts of python creating empty directories under /tmp, which a few days ago I found to number 10,000 subdirs under /tmp. I deleted them all but it did not help performance. Forgive my lack of Unix knowledge, but am I right in assuming that once the directory inode is enlarged to list such an extensive # of subdirs/files, deleting those doesn't shrink the directory inode itself, but leaves a sparse structure that still has to be scanned through by all file accesses? The inode size of my /tmp (ls -ld /tmp) is currently 708KB. That's 172x larger than the starting size of 4096 bytes. Could that be what's slowing down stat and openat calls that hit /tmp ?
Paul W (183 rep)
Dec 16, 2024, 05:30 PM • Last activity: Dec 16, 2024, 08:08 PM
3 votes
2 answers
101 views
Simulated Execution of Redirections
My shell is the Korn Shell, but I think the problem (and its eventual remedy) applies to other shells as well. I usually build a "simulation mode" into my scripts to test potentially destructive/state-changing commands up front. Like this: # export SIMULATE='print -' [...] $SIMULATE /path/to/hazardo...
My shell is the Korn Shell, but I think the problem (and its eventual remedy) applies to other shells as well. I usually build a "simulation mode" into my scripts to test potentially destructive/state-changing commands up front. Like this: # export SIMULATE='print -' [...] $SIMULATE /path/to/hazardous_command When the first line is uncommented the command is not executed but only printed instead. The problem I have is: if the command in question involves some redirection this won't work: $SIMULATE /path/to/hazardous_command > /path/to/file 2>/path/to/other_file Is there any elegant(!) solution I haven't been thinking of as now? I know I could do: if [ -n "$SIMULATE" ] ; then $SIMULATE "/path/to/hazardous_command > /path/to/file 2>/path/to/other_file" else /path/to/hazardous_command > /path/to/file 2>/path/to/other_file fi but this is not really making the code clearer and I would prefer a "plug-in" solution of some sorts, although up to now I came up short. I have also thought about (uncomment either of the export-statements): # export SIMULATE='eval ' # export SIMULATE='print -' [...] $SIMULATE "/path/to/hazardous_command >/path/to/file 2>/path/to/other_file" this would work but this replaces the problem of the redirections with the problem of the quotes: what if the command in question involves quoted strings? Escaping the quotes would work, but ultimately I would still have to maintain two different versions of the command (one to be printed, one to be executed). So, has anybody an idea how to overcome this?
bakunin (683 rep)
Dec 13, 2024, 09:20 AM • Last activity: Dec 13, 2024, 04:44 PM
61 votes
4 answers
11609 views
Is the shell ksh93 dead?
On 2013-01-10 Glenn Fowler posted this to the [ast-users mailing list](https://web.archive.org/web/20151130233422/http://lists.research.att.com/pipermail/ast-users/2013q4/004368.html): >As has been pointed out several times on the AST and UWIN lists, AT&T gives very little support to OpenSouce softw...
On 2013-01-10 Glenn Fowler posted this to the [ast-users mailing list](https://web.archive.org/web/20151130233422/http://lists.research.att.com/pipermail/ast-users/2013q4/004368.html) : >As has been pointed out several times on the AST and UWIN lists, AT&T gives very little support to OpenSouce software, which is why we have so few people involved with our rather large collection of AST software. In spite of this, ksh, nmake, vczip, UWIN and other AST tools continue to be used in several AT&T projects. > It turns out that software isn't the only thing lacking support: both dgk *(David Korn)* (AT&T fellow, 36 years of service) and gsf *(Glenn Fowler)* (AT&T fellow, 29 years of service) have been terminated, effective October 10. Our third major partner, Phong Vo (AT&T fellow, 32 years of service), left a few months ago for Google. The UWIN maintainer, Jeff Fellin, is still with AT&T and provides UWIN support for some critical operations. > Both dgk and gsf will continue to work on AST software, and might actually have more time (at least in the short run) to focus on it. > The download site and mail groups will remain within AT&T for at least the next several months. Our AT&T colleague, dr.ek, AST user and bug detector, will maintain the site. We have secured the astopen.org domain and are investigating non-AT&T hosting options, including a repository with bug tracking. > The process of change will take time; the patience of the user community will be greatly appreciated. Its quite a shock to have 3 weeks to plan personal, career, and hacking futures after working in an environment that has essentially been stable for almost 30 years. The user groups will be informed as plans solidify. [Korn's own wikipedia page](https://en.wikipedia.org/wiki/David_Korn_(computer_scientist)) says he worked for AT&T Labs Research *until 2013..., but he is now working for Google[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed)* . A [dgkorn github user account](https://github.com/dgkorn) was created in November 2014, but it has been the source of exactly 0 public contributions since that time, and subscribes to as many repos. Since 2013, the related mailing-lists have grown progressively less active. For example, the [fourth-quarter ast-developers list for 2013](https://web.archive.org/web/20151130233525/http://lists.research.att.com/pipermail/ast-developers/2013q4/date.html) had posted 156 messages by 2013-12-01, but the same list for [fourth-quarter 2015](https://web.archive.org/web/20151130233555/http://lists.research.att.com/pipermail/ast-developers/2015q4/thread.html) lists only three messages, and this is the last of them: > Subject: Re: [ast-developers] Transitioning ast to GitHub >>> Is there any intention to transition the ast codebase to a source code repository like GitHub? That would make it much easier for the community to contribute. I'm concerned that without such a collaborative environment, ast-related development will stall as bug reports and source-code patches get lost in the ether. >> Does anyone have a full git repo they can publish somewhere (repo.or.cz, github, whatever)? Git server is down for ages, now even www2.research.att.com (204.178.8.28) went down. > This makes one wonder about the future of Kornshell. Has it died? Are we to see no more releases? And, indeed, [though AT&T lists all of the AST links](http://www.research.att.com/software_tools?fbid=FfppKZYg2tq#Software) at their *labs research* landing page, none of these seem to work. These are the same dead links listed at [kornshell.com](http://www.kornshell.com) for download. Even if the current server state should prove only temporary for now, the dried-up mailing-list doesn't seem to bode well. And so, is the korn shell now kaput? Or is there more activity along these lines elsewhere?
mikeserv (59293 rep)
Nov 30, 2015, 08:12 AM • Last activity: Dec 3, 2024, 01:32 PM
0 votes
3 answers
216 views
Find command slow when I'm not piping into awk
I have a script I've used for many years for building a list to some directories, with the following lines: ##Find all scenarios for this sector number find /gsgt/source/scenarios/AT_* -name ${current}"*" -type d | \ awk -F"/" '{print $NF}' > Sector_${current}_list.txt find /gsgt/source/scenarios/AT...
I have a script I've used for many years for building a list to some directories, with the following lines: ##Find all scenarios for this sector number find /gsgt/source/scenarios/AT_* -name ${current}"*" -type d | \ awk -F"/" '{print $NF}' > Sector_${current}_list.txt find /gsgt/source/scenarios/AT_* -name "3T${current}*" -type d | \ awk -F"/" '{print $NF}' >> Sector_${current}_list.txt find /gsgt/source/scenarios/AT_* -name "4T${current}*" -type d | \ awk -F"/" '{print $NF}' >> Sector_${current}_list.txt find /gsgt/source/scenarios/AT_* -name "Sector_${current}*" -type d | \ awk -F"/" '{print $NF}' >> Sector_${current}_list.txt` This gives me a list of only the directory names. The commands take a split second to complete. Recently, we've found a need to start with full path statements in a similar script. I rewrote the section without the pipe into awk as follows: ##Find all scenarios for this sector number, put them into list find /gsgt/source/scenarios/AT_* -name ${current}"*" -type d \ > Sector_${current}_list.txt find /gsgt/source/scenarios/AT_* -name "3T${current}*" -type d \ >> Sector_${current}_list.txt find /gsgt/source/scenarios/AT_* -name "4T${current}*" -type d \ >> Sector_${current}_list.txt find /gsgt/source/scenarios/AT_* -name "Sector_${current}*" -type d \ >> Sector_${current}_list.txt This gives me the same list with full path statements, and works, but it takes *nearly a minute* to complete. It's searching the same tree structure, with the same variable input. Why is the second one, which seems "simpler", so much slower?
atc_ceedee (113 rep)
Jul 20, 2024, 06:15 PM • Last activity: Nov 14, 2024, 07:09 PM
Showing page 1 of 20 total questions