【问题标题】:Linux Terminal Head Command Issue [closed]Linux终端头命令问题[关闭]
【发布时间】:2021-01-11 21:23:53
【问题描述】:

我刚刚开始学习 Linux 终端的基础知识,但遇到了一些问题。我想使用 curl 或 wget 下载文件并显示其内容,但是当我输入 head 命令时,它给了我 html 脚本而不是实际的 csv 内容。这是我的代码:

curl -O http://files.grouplens.org/datasets/movielens/ml-latest-small.zip
unzip ml-latest-small.zip
head -n 12 movies.csv

这是返回的内容:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  <link rel="dns-prefetch" href="https://github.githubassets.com">
  <link rel="dns-prefetch" href="https://avatars0.githubusercontent.com">
  <link rel="dns-prefetch" href="https://avatars1.githubusercontent.com">

但这是我想要的输出:

movieId,title,genres
1,Toy Story (1995),Adventure|Animation|Children|Comedy|Fantasy
2,Jumanji (1995),Adventure|Children|Fantasy
3,Grumpier Old Men (1995),Comedy|Romance
4,Waiting to Exhale (1995),Comedy|Drama|Romance
5,Father of the Bride Part II (1995),Comedy
6,Heat (1995),Action|Crime|Thriller
7,Sabrina (1995),Comedy|Romance
8,Tom and Huck (1995),Adventure|Children
9,Sudden Death (1995),Action
10,GoldenEye (1995),Action|Adventure|Thriller
11,"American President, The (1995)",Comedy|Drama|Romance

有谁知道我做错了什么?

【问题讨论】:

  • 有些不对劲。如果这些是您运行的实际命令并且它们都成功了,那么您下载的文件根本不包含您的预期。完全不清楚为什么从 zip 文件中提取的 CSV 文件会包含 HTML。
  • 另外,这可能更适合 unix.stackexchange.com,因为它更多地处理一些命令行程序的使用而不是脚本。
  • Stack Overflow 用于编程问题,而不是关于使用或配置 Unix 及其实用程序的问题。 Unix & LinuxSuper User 将是解决此类问题的更好地方。

标签: linux csv ssh terminal command-line-interface


【解决方案1】:

嗯——这当然很奇怪——我只是运行了确切的命令而没有错误。

您是否将 CD 放入您创建的新解压缩文件夹中?

pi@raspberrypi:~ $ curl -O http://files.grouplens.org/datasets/movielens/ml-latest-small.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  955k  100  955k    0     0   942k      0  0:00:01  0:00:01 --:--:--  943k
pi@raspberrypi:~ $ unzip ml-latest-small.zip

Archive:  ml-latest-small.zip

   creating: ml-latest-small/
  inflating: ml-latest-small/links.csv  
  inflating: ml-latest-small/tags.csv  
  inflating: ml-latest-small/ratings.csv  
  inflating: ml-latest-small/README.txt  
  inflating: ml-latest-small/movies.csv  

pi@raspberrypi:~ $ cd ml-latest-small/

pi@raspberrypi:~/ml-latest-small $ ls

links.csv  movies.csv  ratings.csv  README.txt  tags.csv

pi@raspberrypi:~/ml-latest-small $ head -n 12 movies.csv

movieId,title,genres
1,Toy Story (1995),Adventure|Animation|Children|Comedy|Fantasy
2,Jumanji (1995),Adventure|Children|Fantasy
3,Grumpier Old Men (1995),Comedy|Romance
4,Waiting to Exhale (1995),Comedy|Drama|Romance
5,Father of the Bride Part II (1995),Comedy
6,Heat (1995),Action|Crime|Thriller
7,Sabrina (1995),Comedy|Romance
8,Tom and Huck (1995),Adventure|Children
9,Sudden Death (1995),Action
10,GoldenEye (1995),Action|Adventure|Thriller
11,"American President, The (1995)",Comedy|Drama|Romance

【讨论】:

  • 对 OP 来说可能不是那么明显。
  • 一开始我没有将 CD 放入新文件,但我只是这样做了,它确实有效。谢谢。
  • 太棒了 :) 另外 - 你所做的这个命令真的很有帮助!运行 head -n /ml-latest-small/12 movies.csv 可能更容易,因此您不必每次都将 CD 放入其中
猜你喜欢
  • 2020-10-09
  • 2013-07-03
  • 2013-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-25
  • 1970-01-01
  • 2011-01-07
相关资源
最近更新 更多