unix

Quick ls command

旧街凉风 提交于 2021-02-05 20:12:21
问题 I've got to get a directory listing that contains about 2 million files, but when I do an ls command on it nothing comes back. I've waited 3 hours. I've tried ls | tee directory.txt , but that seems to hang forever. I assume the server is doing a lot of inode sorting. Is there any way to speed up the ls command to just get a directory listing of filenames? I don't care about size, dates, permission or the like at this time. 回答1: ls -U will do the ls without sorting. 回答2: Try using: find .

How to sort a file in unix both alphabetically and numerically on different fields?

蹲街弑〆低调 提交于 2021-02-05 18:01:35
问题 Please don't think this is a repeat of the "Sorting alphanumeric data in unix" question... I looked at the other answers, and think my case is a bit different! I have data like this: A 192 D 112 D 188 C 091 A 281 B 919 ...And I want to sort first column 1 (alphabetically), and then by column 2 (numerically). I tried using: sort -n -k1,2 ...But this gave me correctly sorted for the first field, but then the wrong sorting for the second field (1000,1002,1003,10,1 ... instead of 1,10,1000,1002

How to sort a file in unix both alphabetically and numerically on different fields?

巧了我就是萌 提交于 2021-02-05 18:01:08
问题 Please don't think this is a repeat of the "Sorting alphanumeric data in unix" question... I looked at the other answers, and think my case is a bit different! I have data like this: A 192 D 112 D 188 C 091 A 281 B 919 ...And I want to sort first column 1 (alphabetically), and then by column 2 (numerically). I tried using: sort -n -k1,2 ...But this gave me correctly sorted for the first field, but then the wrong sorting for the second field (1000,1002,1003,10,1 ... instead of 1,10,1000,1002

How to sort a file in unix both alphabetically and numerically on different fields?

可紊 提交于 2021-02-05 18:00:41
问题 Please don't think this is a repeat of the "Sorting alphanumeric data in unix" question... I looked at the other answers, and think my case is a bit different! I have data like this: A 192 D 112 D 188 C 091 A 281 B 919 ...And I want to sort first column 1 (alphabetically), and then by column 2 (numerically). I tried using: sort -n -k1,2 ...But this gave me correctly sorted for the first field, but then the wrong sorting for the second field (1000,1002,1003,10,1 ... instead of 1,10,1000,1002

How to sort a file in unix both alphabetically and numerically on different fields?

↘锁芯ラ 提交于 2021-02-05 17:58:19
问题 Please don't think this is a repeat of the "Sorting alphanumeric data in unix" question... I looked at the other answers, and think my case is a bit different! I have data like this: A 192 D 112 D 188 C 091 A 281 B 919 ...And I want to sort first column 1 (alphabetically), and then by column 2 (numerically). I tried using: sort -n -k1,2 ...But this gave me correctly sorted for the first field, but then the wrong sorting for the second field (1000,1002,1003,10,1 ... instead of 1,10,1000,1002

mkdir's “-p” option

隐身守侯 提交于 2021-02-05 12:39:15
问题 So this doesn't seem like a terribly complicated question I have, but it's one I can't find the answer to. I'm confused about what the -p option does in Unix. I used it for a lab assignment while creating a subdirectory and then another subdirectory within that one. It looked like this: mkdir -p cmps012m/lab1 This is in a private directory with normal rights ( rlidwka ). Oh, and would someone mind giving a little explanation of what rlidwka means? I'm not a total noob to Unix, but I'm not

no output from unix shell script

十年热恋 提交于 2021-02-05 12:26:24
问题 I have the following shell script (named test ): #!/bin/sh echo "junk" filename="junk" echo $filename filename=`ls -t|head -n1` echo $filename when I run this script there is no output to the terminal. I am using red hat / putty. What am I missing? 回答1: You're accidentally running the system command called test , which produces no output. You need to use ./test instead to find the script in the current directory, whereas test will use the built-in shell command (and even if it didn't, it

no output from unix shell script

我的未来我决定 提交于 2021-02-05 12:26:05
问题 I have the following shell script (named test ): #!/bin/sh echo "junk" filename="junk" echo $filename filename=`ls -t|head -n1` echo $filename when I run this script there is no output to the terminal. I am using red hat / putty. What am I missing? 回答1: You're accidentally running the system command called test , which produces no output. You need to use ./test instead to find the script in the current directory, whereas test will use the built-in shell command (and even if it didn't, it

Why does if [ …something… ]; then echo “Exit status is $?” always emit 0?

让人想犯罪 __ 提交于 2021-02-05 09:46:34
问题 What is the correct way to output an exit status in bash? As far as I know, the exit status called by $? corresponds to the status of the last command executed. The script being worked on has a few conditional checks on the files fed as arguments, for example, a check on whether any files were named at all or if a file exists or not. So I have conditional statements like this: if [ $# -eq 0 ] ; then echo "No file name(s) given! \nExit status=$?" exit if [ ! -e "$fName" ] ; then echo "$fName

create unix alias using a python3 script

爷,独闯天下 提交于 2021-02-05 09:11:45
问题 Well, as we all known, creating an alias in a terminal shell is quite easy: ZZ:~ zhangzhao$ alias c='uname' ZZ:~ zhangzhao$ c Darwin ZZ:~ zhangzhao$ But now I want to do the same thing through a Python3 script. I've checked the ref manual and found these sort of command work can be solved using subprocess module. Then I write the script below: import subprocess subprocess.call(["alias", "c=\'uname\'"]) But note that this operation will not take effect to the shell you are currently using,